Skip to content

perf: unroll first probe in ClassNameFilter.contains()#67

Open
bm1549 wants to merge 1 commit intomainfrom
brian.marks/opt-filter
Open

perf: unroll first probe in ClassNameFilter.contains()#67
bm1549 wants to merge 1 commit intomainfrom
brian.marks/opt-filter

Conversation

@bm1549
Copy link
Copy Markdown
Contributor

@bm1549 bm1549 commented Apr 9, 2026

What Does This Do

Unroll the first hash probe in ClassNameFilter.contains() out of the loop, since it is the most common path (hit on first try). Also inline the rehash function in the collision loop to avoid method call overhead.

Motivation

Benchmarking ClassNameFilterBenchmark against spring-web.jar showed significant multi-threaded improvement:

Single-threaded:

cacheSize Baseline (us/op) After (us/op) Change
4096 6.458 ± 0.91 6.166 ± 0.86 -4.5%
16384 6.310 ± 0.10 6.413 ± 0.45 +1.6% (noise)
65536 6.654 ± 0.70 6.304 ± 0.15 -5.3%

Multi-threaded (10 threads):

cacheSize Baseline (us/op) After (us/op) Change
4096 12.006 ± 3.77 8.726 ± 2.04 -27.3%
16384 11.112 ± 3.03 9.327 ± 1.50 -16.1%
65536 10.865 ± 2.91 8.604 ± 0.87 -20.8%
1048576 11.140 ± 2.54 8.695 ± 1.37 -22.0%

The unrolled first probe avoids loop setup overhead and likely reduces contention in multi-threaded scenarios.

Additional Notes

  • Only contains() is changed; add() is unchanged
  • All existing tests pass

Contributor Checklist

Jira ticket: N/A — performance optimization, no ticket

🤖 Generated with Claude Code

Unroll the first hash probe out of the loop since it is the most common
path (hit on first try). Also inline the rehash function in the
collision loop to avoid method call overhead.

Benchmark results (ClassNameFilterBenchmark, spring-web.jar dataset):

Single-threaded:
  cacheSize=4096:    6.458 -> 6.166 us/op  (-4.5%)
  cacheSize=65536:   6.654 -> 6.304 us/op  (-5.3%)

Multi-threaded (10 threads):
  cacheSize=4096:   12.006 -> 8.726 us/op  (-27.3%)
  cacheSize=16384:  11.112 -> 9.327 us/op  (-16.1%)
  cacheSize=65536:  10.865 -> 8.604 us/op  (-20.8%)
  cacheSize=1048576:11.140 -> 8.695 us/op  (-22.0%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mcculls mcculls self-requested a review April 9, 2026 16:22
@bm1549 bm1549 marked this pull request as ready for review April 9, 2026 17:43
@bm1549 bm1549 requested a review from a team as a code owner April 9, 2026 17:43
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