Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement non-wildcard subscription management#2238

Open
jboshoven-emporia wants to merge 1 commit intodotnet:masterfrom
jboshoven-emporia:non-wildcard-improvements
Open

Implement non-wildcard subscription management#2238
jboshoven-emporia wants to merge 1 commit intodotnet:masterfrom
jboshoven-emporia:non-wildcard-improvements

Conversation

Copy link

jboshoven-emporia commented Mar 3, 2026

In a world where there are a ton of clients with many subscriptions that are not wildcard, it can get really expensive to loop through the entire list of subscribers. This change breaks the subscribers down into two lists, one for wildcards and one without. You can see in DispatchApplicationMessage that if there is a _simpleTopicToSessions it will be grabbed first and added to all wildcard sessions. If there are no wildcard sessions, this operation is exceedingly cheap. The rest of the change outside of this spot is pretty much just plumbing.

This change is based on this PR #2175 by AlexNik4 to try and solve this issue #2174.

This change also stops copying the hash set on publish. These sets have become copy on write and then the entire session management lock was removed at the expense of more garbage during subscribe/unsubscribe. This garbage was paid for every publish anyway.

In a world where there are a ton of clients with many subscriptions that are not wildcard, it can get really expensive to loop through the entire list of subscribers. This change breaks the subscribers down into two lists, one for wildcards and one without. You can see in `DispatchApplicationMessage` that if there is a `_simpleTopicToSessions` it will be grabbed first and added to all wildcard sessions. If there are no wildcard sessions, this operation is exceedingly cheap. The rest of the change outside of this spot is pretty much just plumbing.

This change is based on this PR dotnet#2175 by AlexNik4 to try and solve this issue dotnet#2174.

This change also stops copying the hash set on publish. These sets have become copy on write and then the entire session management lock was removed at the expense of more garbage during subscribe/unsubscribe. This garbage was paid for every publish anyway.
_sessionsManagementLock.EnterReadLock();
try
MqttSessionLists subscriberSessions;
if (_simpleTopicToSessions.TryGetValue(applicationMessage.Topic , out var matchedSimpleTopicSessions))
Copy link
Author

jboshoven-emporia Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the read that returns an iterator with a copy of the values.

Copy link
Author

jboshoven-emporia commented Mar 3, 2026

@dotnet-policy-service agree company="Emporia Energy"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant