Skip to content

perf: replace set membership checks with chained == in GAP parser#203

Closed
bdraco wants to merge 1 commit into
mainfrom
optimize-set-membership-to-chained-eq
Closed

perf: replace set membership checks with chained == in GAP parser#203
bdraco wants to merge 1 commit into
mainfrom
optimize-set-membership-to-chained-eq

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented Mar 15, 2026

Summary

  • Replace 3 gap_type_num in {A, B} set-literal membership checks with chained == comparisons in _uncached_parse_advertisement_bytes
  • In Cython-compiled code, x in {A, B} creates a frozenset lookup that benchmarks ~2.4x slower than x == A or x == B (0.051 us vs 0.021 us per check)
  • These checks fire on every GAP record in the parse loop, so the improvement compounds with advertisement volume

Test plan

  • Existing tests pass (no behavioral change, pure refactor)
  • Verify Cython compilation succeeds

In Cython-compiled code, `x in {A, B}` creates a frozenset lookup
that benchmarks ~2.4x slower than `x == A or x == B` per check.
This fires on every GAP record in the parse loop.
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7a74ee9) to head (f5865f1).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #203   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          255       255           
  Branches        38        38           
=========================================
  Hits           255       255           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 15, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing optimize-set-membership-to-chained-eq (f5865f1) with main (7a74ee9)

Open in CodSpeed

@bdraco bdraco closed this Mar 15, 2026
@bdraco bdraco deleted the optimize-set-membership-to-chained-eq branch March 15, 2026 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant