Skip to content

Fix review findings in the screened search - #190

Merged
mxsm merged 1 commit into
mainfrom
mxsm/search-review-fixes
Nov 20, 2026
Merged

mxsm merged 1 commit into
mainfrom
mxsm/search-review-fixes

Conversation

@mxsm

@mxsm mxsm commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Fixes the seven findings from the review of #187 and #188 (#189).

Summary

  • aarch64 cutoff (finding 3): find_screen_limit(needle) stops find's screen at 64 bytes for 2–3-byte needles and at 160 bytes for 4–15-byte needles, on aarch64 only. That is where the ubuntu-24.04-arm sweep from Use the screened short-needle search for find, contains, and rfind #188 showed NEON memmem winning: up to 1.26x slower with the screen for 2-byte needles from 64 bytes, and 1.13x for 8-byte needles at 192 bytes. Longer needles gained up to 256 bytes on aarch64 (0.14–0.40x), and every needle did on x86_64. rfind won everywhere below 256 bytes on both, so it is unchanged
  • one-call-site rule (findings 1, 2):
    • the comment above std_contains and std_rfind now states the rule the instruction-count gate depends on: each wrapper is the only call site of its std search with a &str pattern
    • the comment on contains_str's catch-all arm no longer blames the gate failure on a second out-of-line arm
    • str::find stays a direct call in the two cold hand-offs, and the comment says why. A std_find wrapper made std_rfind 9–21% slower on 512 B–4 KiB haystacks in a default 16-codegen-unit build, with no difference at one unit. Without the wrapper, 512 B and 1 KiB rfind matched main exactly
  • ShortSearch docs (finding 4): Found and TooManyFalseCandidates now describe both scan directions
  • shared screen (finding 5): find_short and rfind_short share screen_block, an #[inline(always)] function that returns the 16-position hit mask
  • docs (finding 6): the crate docs, contains/find docs, README, and CHANGELOG describe the paths for needles over 32 bytes, contains on targets without SIMD, and the aarch64 limit
  • non-SIMD coverage (finding 7):
    • the layout-32-bit job also runs transform_search and search for i686-pc-windows-msvc, where std has no SIMD contains
    • a library test runs the screened contains path with full blocks and the hand-off on every target. Making the hand-off return false fails it

Measured impact

Same-binary A/B against main, i7-11700K, default codegen units, two rounds. Every case is ×0.92–1.03:

  • rfind, 512 B–4 KiB: ×0.99–1.03
  • find, 32 B with an 8-byte needle: 10.5–10.7 → 9.8–10.0 ns
  • contains, 40 B with a 32-byte needle: 9.0–9.1 → 8.3–8.4 ns

Search thresholds on aarch64 (ubuntu-24.04-arm). Each cell is find's CheetahString time against the faster of str and memmem in the same run, geometric mean of four cases; lower is better. Columns: #175's rules, then #188, then this PR:

Haystack 2-byte needle 4-byte needle 8-byte needle 16-byte needle
64 B 1.17, 1.21, 1.20 1.12, 0.96, 0.99 1.12, 0.84, 0.87 1.07, 0.27, 0.27
96 B 1.16, 1.30, 1.19 1.12, 1.02, 1.03 1.11, 0.93, 0.98 1.05, 0.35, 0.37
128 B 1.13, 1.33, 1.16 1.12, 1.06, 1.07 1.08, 1.01, 1.04 1.05, 0.39, 0.40
160 B 1.15, 1.37, 1.18 1.10, 1.11, 1.11 1.08, 1.09, 1.09 1.04, 0.38, 0.40
192 B 1.11, 1.39, 1.14 1.10, 1.14, 1.11 1.08, 1.22, 1.09 1.04, 0.42, 0.44

The cells #188 made slower return to their pre-#188 level, and the 16-byte needles keep their gains. Over the whole sweep, against the faster backend:

Runner find rfind contains
aarch64, #188 0.687 0.532 1.118
aarch64, this PR 0.696 0.539 1.111
x86_64, #188 0.663 0.562 1.121
x86_64, this PR 0.657 0.558 1.153

The x86_64 contains change is run-to-run noise: its code is unchanged on x86_64, and the instruction-count gate reports identical counts for every scenario.

Verification

  • cargo fmt --check; clippy -D warnings for all targets with all features, no default features, and serde,bytes,simd
  • cargo test --all-features: 250 passed (2 new); --no-default-features --lib: 19 passed
  • rustdoc without warnings; cargo +1.95.0 check --all-features; Python tests pass
  • the i686 tests ran in this PR's layout-32-bit job: search 5 passed, transform_search 12 passed
  • instruction-count gate: every scenario identical to main

Closes #189

🤖 Generated with Claude Code

- aarch64: find screens only up to 64 bytes for 2- and 3-byte needles and
  up to 160 bytes for 4- to 15-byte needles, where NEON memmem won on the
  ubuntu-24.04-arm runner; other needles and targets keep 256 bytes
- document the one-call-site rule on std_contains and std_rfind, and why
  str::find is the exception: a std_find wrapper moved core's shared
  Two-Way code to another codegen unit in default builds and made
  std_rfind on long haystacks 9 to 21% slower
- correct the contains_str comment that blamed the gate failure on a
  second out-of-line arm
- ShortSearch documents both scan directions
- find_short and rfind_short share screen_block
- crate docs, method docs, README, and CHANGELOG describe the paths for
  needles over 32 bytes and the aarch64 limit
- run transform_search and search on the i686 job, where std has no SIMD
  contains, and unit-test the screened contains path with full blocks on
  every target

Closes #189

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 09:30

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@mxsm
mxsm merged commit 786fa4c into main Nov 20, 2026
19 checks passed
@mxsm
mxsm deleted the mxsm/search-review-fixes branch November 20, 2026 09:37
@mxsm mxsm mentioned this pull request Nov 20, 2026
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.

Follow-ups from the review of #187 and #188

2 participants