Skip to content

perf(wacore): drop the proto PartialEq anchor from the skdm-only check - #846

Merged
jlucaso1 merged 1 commit into
mainfrom
perf/drop-proto-eq-anchor
Jun 11, 2026
Merged

jlucaso1 merged 1 commit into
mainfrom
perf/drop-proto-eq-anchor

Conversation

@jlucaso1

Copy link
Copy Markdown
Collaborator

Problem

cargo llvm-lines flagged prost's derived PartialEq as the largest codegen item in wacore (Message::eq alone is 4.2k IR lines, with the whole nested tree behind it). In the release binary that materializes as 94 KiB of .text across 148 eq functions, and symbol tracing showed exactly one production caller keeping all of it alive: the skdm-only check in wacore::messages, which compares the carrier-stripped message against Message::default().

Change

encoded_len() == 0 is the same predicate: under proto2 presence rules a field only contributes encoded bytes when it is set, so zero encoded length means every remaining field is unset, which is exactly equality with Message::default(). It routes through waproto::codec::message_encoded_len, the tree already pinned by #842, so no new codegen appears anywhere.

Cost-wise the paths are equivalent where it matters: for a true skdm-only message both walks visit every (unset) field once; the fast path above the slow path still short-circuits typical content messages before either runs.

Measured

Release bin: .text 11.65 MiB -> 11.55 MiB (-102 KiB); proto eq impls 148 -> 0. Unlike the Dockerfile flags, this one applies to stable and nightly consumers alike.

Tests

wacore (1008) and lib (830) suites pass; the skdm-only behavior is locked by the existing dedicated tests.

The slow path compared the stripped message against Message::default(), which was the only production caller of prost's derived PartialEq and kept the eq impls for the entire message tree alive in every binary (94 KiB across 148 functions). Under proto2 presence rules a field only contributes encoded bytes when set, so encoded_len == 0 is the same predicate; it reuses the codec tree already pinned by waproto::codec.

Measured on the release bin: .text 11.65 MiB to 11.55 MiB (-102 KiB), proto eq impls 148 to 0. Applies to stable and nightly builds alike.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6c1e8288-f4ba-4276-babe-f2b16380d3f2

📥 Commits

Reviewing files that changed from the base of the PR and between 7c46513 and 8809918.

📒 Files selected for processing (1)
  • wacore/src/messages.rs

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of sender-key distribution message detection and handling.

Walkthrough

The PR optimizes message validation in wacore/src/messages.rs by replacing a full message comparison with a direct protobuf encoded size check to detect sender-key-only distribution messages.

Changes

Sender-key distribution detection optimization

Layer / File(s) Summary
Protobuf size-based detection
wacore/src/messages.rs
is_sender_key_distribution_only now checks waproto::codec::message_encoded_len(msg) == 0 instead of comparing the message object against the default value, simplifying the predicate while maintaining the same functional semantics.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

performance

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: replacing PartialEq with encoded_len() check for performance optimization in the skdm-only check.
Description check ✅ Passed The description is well-related to the changeset, explaining the problem, solution, measured improvements, and test validation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/drop-proto-eq-anchor

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

@codspeed-hq

codspeed-hq Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 140 untouched benchmarks


Comparing perf/drop-proto-eq-anchor (8809918) with main (7c46513)

Open in CodSpeed

@jlucaso1
jlucaso1 merged commit a3a0a57 into main Jun 11, 2026
14 checks passed
@jlucaso1
jlucaso1 deleted the perf/drop-proto-eq-anchor branch June 11, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant