fix(mesh): skip pre-encryption packet copy when MQTT does not need it#10434
Open
DatanoiseTV wants to merge 1 commit into
Open
fix(mesh): skip pre-encryption packet copy when MQTT does not need it#10434DatanoiseTV wants to merge 1 commit into
DatanoiseTV wants to merge 1 commit into
Conversation
Router::send unconditionally allocCopy/release'd a pre-encryption clone of every relayed packet, even on builds where MQTT was excluded (MESHTASTIC_EXCLUDE_MQTT) or runtime-disabled (mqtt module nullptr or moduleConfig.mqtt.enabled=false) or when the packet was a relay rather than from us. The copy is only fed to MQTT::onSend, so guard the alloc on the same predicate the call site already used. On nodes near pool exhaustion this halves the alloc rate on the hot path.
8 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Reduces packet-pool pressure in Router::send by avoiding an unconditional pre-encryption packet clone when MQTT is compile-time excluded or runtime-disabled, aligning allocation behavior with the existing MQTT publish guard.
Changes:
- Allocate the pre-encryption
p_decodedclone only when MQTT publishing will occur. - Guard
packetPool.release()calls to avoid releasing a null pointer. - Use the existence of
p_decodedto gatemqtt->onSend()and release in the MQTT-enabled build.
Comment on lines
+379
to
+384
| const bool needDecodedForMqtt = moduleConfig.mqtt.enabled && isFromUs(p) && mqtt; | ||
| if (needDecodedForMqtt) { | ||
| DEBUG_HEAP_BEFORE; | ||
| p_decoded = packetPool.allocCopy(*p); | ||
| DEBUG_HEAP_AFTER("Router::send", p_decoded); | ||
| } |
Comment on lines
+396
to
399
| if (p_decoded) { | ||
| mqtt->onSend(*p, *p_decoded, chIndex); | ||
| packetPool.release(p_decoded); | ||
| } |
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.
Router::send unconditionally allocCopy/release'd a pre-encryption clone
of every relayed packet, even on builds where MQTT was excluded
(MESHTASTIC_EXCLUDE_MQTT) or runtime-disabled (mqtt module nullptr or
moduleConfig.mqtt.enabled=false) or when the packet was a relay rather
than from us. The copy is only fed to MQTT::onSend, so guard the alloc
on the same predicate the call site already used. On nodes near pool
exhaustion this halves the alloc rate on the hot path.
Split out from #10424 per @thebentern's request — single-concern PR.
Build verification
pio run -e t-deck-tftsucceeds, no new warnings.Attestations
t-deck-tftonly.