perf(jid): compare structured JID attributes without rendering them - #1176
Merged
Conversation
`ValueRef::as_str()` renders a `Jid` variant into an owned `String` just so the caller can compare it to a literal. `ValueRef` already implements `PartialEq<str>`, which walks the JID's display form against the needle without building it. Applied to the server-origin checks in pair, passkey and device notification handling, and to `NodeFilter`'s attribute match. Equivalence is what matters here, since two of these gate whether a stanza is honored at all: `comparing_a_jid_value_matches_comparing_its_rendered_form` asserts the two forms agree over user/device/agent/group/lid shapes and the server-only JID that those checks actually compare against.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR replaces redundant string conversions with direct ChangesValueRef matching updates
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
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.
A decoded JID attribute is kept structured as
ValueRef::Jid. Comparing it to a literal viav.as_str() == SERVER_JIDthrows that away:as_str()renders the JID into an ownedStringpurely to be compared and dropped.ValueRefalready implementsPartialEq<str>, which walks the display form against the needle without building it.Applied to the server-origin checks in
pair.rs,passkey/flow.rs(×2) and device-notification handling, plusNodeFilter's attribute match.Equivalence
Two of these gate whether a stanza is honored at all ("only honor a server request"), so this is not a place to assume the two forms agree — I checked.
comparing_a_jid_value_matches_comparing_its_rendered_formassertsv == needlematchesv.as_str() == needleacross user, device, agent, group, lid and broadcast shapes, for both theJidandStringvariants, and specifically for the server-only JID (s.whatsapp.net, empty user) — which is the shape those checks actually compare against, and the one the fast parser declines to handle.Deliberately not included
The same sweep also proposed
node.get_attr("from").and_then(|v| v.as_str().parse().ok())→v.to_jid()forServerAck. I left that out: measured against the old form, it is not equivalent.Displayomits the agent for servers whererenders_agent()is false, so stringify-then-reparse silently drops it whileto_jid()preserves it:to_jid()is arguably the more faithful reading — the agent came off the wire — but it changes an observable field of a published event, andEventpayloads are a frozen API. That belongs in its own change with its own justification, not smuggled into a perf PR.Found by a two-model performance sweep (Claude Opus 5 and Codex gpt-5.6-sol). Codex measured the comparison shortcut in isolation; note these are low-frequency control-flow paths, so the aggregate gain is modest — the durable value is not undoing the structured representation the decoder went to the trouble of keeping.