perf(nodedb): bind encode-loop entries by const reference - #11780
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe protobuf encoding loops in current and legacy node database code now iterate entries by const reference. Encoding behavior, error handling, and control flow remain unchanged. ChangesEncoding iteration updates
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~3 minutes Merge Risk: ⚪ Minimal · up to This change removes unnecessary copies while protobuf-encoding node database entries without altering the encoding flow. No current merge-blocking risk remains. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⚡ Try this PR in the Web FlasherNote Building this pull request… the flash button, badges and supported-board |
cppcheck (iterateByValue) flagged five range-for loops in the NodeDatabase pb_callbacks that copy a whole protobuf entry off the vector only to pass its address to pb_encode_submessage(), which takes a const void *. Bind by const reference instead. Drops one meshtastic_NodePositionEntry, NodeTelemetryEntry, NodeStatusEntry, NodeEnvironmentEntry and NodeInfoLite_Legacy copy per node per encode pass; these run on every nodes.proto save. The nodes_tag loop in NodeDB.cpp is intentionally left as a by-value copy: it mutates item.snr_q4/item.snr to the on-disk quantized form before encoding, so it is a working copy rather than a redundant one. cppcheck does not flag it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
9689a6c to
f143c45
Compare
Integrate meshtastic/firmware meshtastic#11732 (73c4110), meshtastic#11780 (3829806), and meshtastic#11782 (42d32fc). Preserve the Superbase runtime Bluetooth, navigation, notification, GPS and radio customizations. Add PhoneAPI config-dump regressions to the mandatory native suite and pin the reviewed integration with normalized source hashes. Validation before commit: Muzi build, source preservation audit, Trunk formatting and production-body nRF52 Bluetooth sanitizer checks passed. Full native CI runs on this commit.
What
cppcheck's
iterateByValuecheck flagged five range-for loops in theNodeDatabasenanopb encode callbacks:All five do the same thing: copy an entire protobuf entry off the vector purely to hand its address to
pb_encode_submessage(), which takes aconst void *. Binding byconst auto &removes the copy with no behavioral change.Per encode pass this drops one copy per node of
meshtastic_NodePositionEntry,NodeTelemetryEntry,NodeStatusEntry,NodeEnvironmentEntryandNodeInfoLite_Legacy. These callbacks run on everynodes.protosave.Note for reviewers
The
nodes_tagloop atsrc/mesh/NodeDB.cpp:265is deliberately left by-value and is not part of this change. It is not a redundant copy — it mutatesitem.snr_q4/item.snrinto the on-disk quantized form before encoding, so it is a working copy. cppcheck correctly does not flag it; converting it would either fail to compile or corrupt the in-memory node list.Three unrelated pre-existing cppcheck findings remain in
NodeDB.cpp(functionStaticongetNodeId,constVariableat :3658,constVariablePointerat :3891). Left alone to keep this diff scoped to theiterateByValueset.Testing
Native suites on macOS (
native-macos), both green:test_nodedb_v25_roundtrip— 8 tests, 0 failures — exercises the fourNodeDB.cppcallbackstest_nodedb_legacy_migration— 9 tests, 0 failures — exercises theNodeDBLegacyMigration.cppcallbackcppcheck 2.20.0 re-run on both files: no
iterateByValuefindings remain. (Invoked directly — a localpio checksilently downgrades to cppcheck 2.11 and is not a valid reproduction of CI.)trunkpre-commit hook clean on both files.🤝 Attestations
No on-device testing was performed — verification was native test suites plus static analysis only. The change is a compile-time binding change in serialization paths shared by all targets, so it is not variant-specific, but a sanity check that a real device still saves and reloads its NodeDB across a reboot would be welcome.
Summary by CodeRabbit