Allow user properties as pre-encoded UTF-8 binary buffer#2228
Merged
chkr1011 merged 9 commits intodotnet:masterfrom Dec 18, 2025
Merged
Allow user properties as pre-encoded UTF-8 binary buffer#2228chkr1011 merged 9 commits intodotnet:masterfrom
chkr1011 merged 9 commits intodotnet:masterfrom
Conversation
Contributor
Author
|
@dotnet-policy-service agree |
Contributor
Author
|
There is a breaking change in dotnet 10, that doesn't allow VSTest runner when using dotnet test. It is recommended to switch to Microsoft.Test.Platform (MTP). I made the required changes in this PR, that the test github workflow can run successfully. Details under: https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test |
Contributor
Author
|
Avoid failing build workflow, by only signing the package when executing the pipeline from the main repo, not from a fork |
chkr1011
reviewed
Dec 7, 2025
chkr1011
reviewed
Dec 13, 2025
chkr1011
reviewed
Dec 13, 2025
chkr1011
requested changes
Dec 16, 2025
Collaborator
chkr1011
left a comment
There was a problem hiding this comment.
Just a few minor changes, after that I will merge the PR.
…rformance and add deprecation warnings for legacy methods
Contributor
Author
|
Had to update a few more places, that also the samples and tests use only the nonobsolete methods |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue:
When extensively using MQTT v5 user properties, handling the key and value as string has two major downsides (allocation time and garbage collection). Keys can use string interning or defined as const but the values (when they are changing) can cause high allocation rate and latency spikes when the garbage collector has to collect them.
Proposal:
Allow value of MQTT v5 user properties to be added as bytes (pre-encoded UTF-8 binary buffer), using performance optimized dotnet types like ReadOnlyMemory. The same optimization was already implemented in version 5.x for the payload of the MQTT message itself.
Outlook:
The current implementation optimizes the MQTT message send path, it would be also possible to optimize the receive path and handling values of user properties only as ReadOnlyMemory and just allocate the string on demand. I didn't implement that yet, as this would require more API changes and might even have negative consequences (when user property values are read multiple times, caching would be required).
Pull Request contains the implementation of the proposal, including tests for binary user properties, a sample demonstrating publishing a message with binary user properties (
Samples/Client/Client_Publish_Samples.cs) and minor fixes for consistency and correctness.