Repository navigation
Conversation
Fewer allocations when keep-alive is not set => better performance
de-sh
force-pushed
the
perf/lazy-sleep-alloc
branch
from
April 5, 2026 07:22
6d374cf to
e876363
Compare
thehouseisonfire
added a commit
to thehouseisonfire/rumqtt
that referenced
this pull request
Apr 24, 2026
thehouseisonfire
added a commit
to thehouseisonfire/rumqtt
that referenced
this pull request
Apr 29, 2026
…etime (MQTT 5 §3.3.2.3.4) Topic aliases in MQTT 5 are scoped to a single network connection and must not survive across reconnects. Previously the single `topic_alises` map was never cleared on reconnect, causing alias-only publishes to be replayed with empty topics (protocol-invalid) or stale mappings from a previous connection. Changes: - Split `topic_alises` into `incoming_topic_aliases` / `outgoing_topic_aliases` to distinguish server-to-client from client-to-server alias directions. - Clear both maps and reset `broker_topic_alias_max` on CONNACK, clean(), and session reset via `reset_connection_scoped_state()`. - During replay (`clean` / `EventLoop::clean`), resolve alias-only publishes using the outgoing alias map captured before the reset. Publishes whose topic cannot be recovered are dropped with the new `PublishNoticeError::TopicAliasReplayUnavailable(alias)` instead of being sent with an empty topic. - Strip topic-alias from replayed publishes (the alias value is meaningless on a new connection) and re-record the mapping from topic-bearing publishes encountered during replay so later alias-only publishes in the same batch can be resolved. - Store the full topic in `outgoing_pub` tracking (via `publish_for_replay_tracking`) so collision-replay also has the topic available even if the original publish used an alias-only form. - DISCONNECT with `ProtocolError` on unknown incoming aliases (early return instead of fall-through after `handle_protocol_error`). - Extract `validate_outgoing_topic_alias`, `record_outgoing_topic_alias`, `publish_topic_alias`, and `strip_publish_topic_alias` helpers for clarity. Roughly maps to upstream PR bytebeamio#1040. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
thehouseisonfire
added a commit
to thehouseisonfire/rumqtt
that referenced
this pull request
Jul 20, 2026
thehouseisonfire
added a commit
to thehouseisonfire/rumqtt
that referenced
this pull request
Jul 20, 2026
…etime (MQTT 5 §3.3.2.3.4) Topic aliases in MQTT 5 are scoped to a single network connection and must not survive across reconnects. Previously the single `topic_alises` map was never cleared on reconnect, causing alias-only publishes to be replayed with empty topics (protocol-invalid) or stale mappings from a previous connection. Changes: - Split `topic_alises` into `incoming_topic_aliases` / `outgoing_topic_aliases` to distinguish server-to-client from client-to-server alias directions. - Clear both maps and reset `broker_topic_alias_max` on CONNACK, clean(), and session reset via `reset_connection_scoped_state()`. - During replay (`clean` / `EventLoop::clean`), resolve alias-only publishes using the outgoing alias map captured before the reset. Publishes whose topic cannot be recovered are dropped with the new `PublishNoticeError::TopicAliasReplayUnavailable(alias)` instead of being sent with an empty topic. - Strip topic-alias from replayed publishes (the alias value is meaningless on a new connection) and re-record the mapping from topic-bearing publishes encountered during replay so later alias-only publishes in the same batch can be resolved. - Store the full topic in `outgoing_pub` tracking (via `publish_for_replay_tracking`) so collision-replay also has the topic available even if the original publish used an alias-only form. - DISCONNECT with `ProtocolError` on unknown incoming aliases (early return instead of fall-through after `handle_protocol_error`). - Extract `validate_outgoing_topic_alias`, `record_outgoing_topic_alias`, `publish_topic_alias`, and `strip_publish_topic_alias` helpers for clarity. Roughly maps to upstream PR bytebeamio#1040. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
Fewer allocations when keep-alive is not set => better performance
Using a perf benchmark against the client, I was able to confirm 2x througput and ~N fewer allocations.
Regarding the
Duration::MAXchangeThis was a latent spin hazard.
sleep(Duration::ZERO)produces a future that is ready instantly. If thatselect!branch fires on every call toselect(). That would be a silent busy-loop: no panic, no log, just 100% CPU usage and also, no keepalives sent, which is whyDuration::MAXmakes more sense here.Type of change
Performance improvement, should not break anything. Impact is clearest against v4 EventLoop that that has no keepalive configured.
Checklist:
cargo fmtCHANGELOG.mdif it's relevant to the users of the library. If it's not relevant mention why.