Loader/TLS: use memchr::memmem SIMD scan in tls::patch #2956

Open
github-bot wants to merge 1 commit from github-bot/gh-2956 into main AGit
Owner

@⁠RVZO6 on GitHub · 2026-11-26 01:30 UTC · original
RVZO6:rvzo/tls-memmem-fast → main · +69 −5 · 3 files · 1 commits · open

Replace the byte-by-byte .text scan in crates/victory-loader/src/tls.rs::patch for mov r64, gs:[0x58] with memchr::memmem::Finder targeting the 5-byte [0x25, 0x58, 0, 0, 0] suffix, using the existing workspace memchr dependency.

Output is bit-identical to the bytewise scanner (verified by memmem_patch_matches_bytewise_oracle across mixed encodings, prefixes, false-positive suffixes, and boundary offsets).

Measured (--release, median of 3 runs)

  • bench_tls_patch_64mb (64 MiB buffer with 32,768 mov r64, gs:[0x58] sites): 39.79 ms → 5.51 ms (7.22×, -86.2%)

Verification

  • Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, --locked, default + --tests + --features diagnostics clippy, xtask policy, full workspace tests): RVZO6/VIctory CI run #45734072839 (green, combined Wave 7 check on 63bcca4).
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon).

**@⁠RVZO6** on GitHub · 2026-11-26 01:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2956) `RVZO6:rvzo/tls-memmem-fast` → `main` · +69 −5 · 3 files · 1 commits · open Replace the byte-by-byte `.text` scan in `crates/victory-loader/src/tls.rs::patch` for `mov r64, gs:[0x58]` with `memchr::memmem::Finder` targeting the 5-byte `[0x25, 0x58, 0, 0, 0]` suffix, using the existing workspace `memchr` dependency. Output is bit-identical to the bytewise scanner (verified by `memmem_patch_matches_bytewise_oracle` across mixed encodings, prefixes, false-positive suffixes, and boundary offsets). ### Measured (`--release`, median of 3 runs) - `bench_tls_patch_64mb` (64 MiB buffer with 32,768 `mov r64, gs:[0x58]` sites): **39.79 ms → 5.51 ms (7.22×, -86.2%)** ### Verification - Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, `--locked`, default + `--tests` + `--features diagnostics` clippy, `xtask policy`, full workspace tests): [RVZO6/VIctory CI run #45734072839](https://github.com/RVZO6/VIctory/actions/runs/45734072839) (green, combined Wave 7 check on `63bcca4`). - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Replace byte-by-byte .text scanning in tls::patch with memchr::memmem::Finder
for the 5-byte [0x25, 0x58, 0, 0, 0] suffix of mov r64, gs:[0x58], using
the existing workspace memchr dependency (bit-identical patch output).

Measured (--release bench_tls_patch_64mb, median of 3 runs, 64 MiB / 32,768 hits):
- 39.79 ms -> 5.51 ms (7.22x, -86.2%)

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:33 +00:00
github-bot force-pushed github-bot/gh-2956 from 2da556ade6 to 47880d38dc 2026-11-26 07:27:34 +00:00 Compare
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:47 UTC · original · edited 2026-11-26 07:19 UTC

Automated triage for the maintainers.

Needs the maintainer's decision. Thanks for 47880d3. The benchmark and its figures from the title's binary are gone, and memmem_patch_matches_bytewise_oracle remains. I re-read tls::patch (crates/victory-loader/src/tls.rs): it is still equivalent to the byte-by-byte scan, and the code.len() < LOAD_LEN early return matches the old loop bound.

What's left is not a code issue. The PR adds memchr as a new dependency of victory-loader (Cargo.toml, Cargo.lock) to save about 35 ms once per launch, and whether that trade is worth it is the maintainer's call.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2956#issuecomment-7183804751) · edited 2026-11-26 07:19 UTC <!-- victory-triage v1 head=47880d38dc7ec09e65c7dda9ef184ec060a4ef3f verdict=needs-work at=2026-11-26T07:19:08Z --> Automated triage for the maintainers. **Needs the maintainer's decision.** Thanks for 47880d3. The benchmark and its figures from the title's binary are gone, and `memmem_patch_matches_bytewise_oracle` remains. I re-read `tls::patch` (`crates/victory-loader/src/tls.rs`): it is still equivalent to the byte-by-byte scan, and the `code.len() < LOAD_LEN` early return matches the old loop bound. What's left is not a code issue. The PR adds `memchr` as a new dependency of `victory-loader` (`Cargo.toml`, `Cargo.lock`) to save about 35 ms once per launch, and whether that trade is worth it is the maintainer's call. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠RVZO6 on GitHub · 2026-11-26 06:56 UTC · original

Addressed triage feedback in 47880d3:

  • Removed the #[ignore] bench_tls_patch_64mb benchmark test and its comment referencing binary sizes/hit counts (docs/asset-policy.md), keeping memmem_patch_matches_bytewise_oracle.
  • Verified green on Windows MSVC + WARP SM 6.6 CI (run 45768895488): 37 passed, 0 failed in victory-loader, both clippy profiles, and xtask policy. Not run: the title; any hardware GPU.
**@⁠RVZO6** on GitHub · 2026-11-26 06:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2956#issuecomment-7184937035) Addressed triage feedback in `47880d3`: - Removed the `#[ignore]` `bench_tls_patch_64mb` benchmark test and its comment referencing binary sizes/hit counts (`docs/asset-policy.md`), keeping `memmem_patch_matches_bytewise_oracle`. - Verified green on Windows MSVC + WARP SM 6.6 CI ([run 45768895488](https://github.com/RVZO6/VIctory/actions/runs/45768895488)): 37 passed, 0 failed in `victory-loader`, both clippy profiles, and `xtask policy`. **Not run:** the title; any hardware GPU.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:50 UTC · original · reviewed

Reviewed and verified against main (63bcca43) on Windows 11 — clean, mathematically equivalent to the byte-by-byte scan, and ready to merge (note: functionally overlaps with #188's SSE2 scanner, and based on main without #1192's short/empty-section guard):

  • Reuses memchr = "2.8.3" already present in Cargo.lock (passes --locked with zero new external crates).
  • crates/victory-loader/src/tls.rs:78-115 searches for the 5-byte invariant tail [0x25, 0x58, 0, 0, 0] starting at pos = 4, recovers i = hit - 4, checks the exact same 9-byte pattern (LOAD_LEN = 9), and advances pos = i + LOAD_LEN + 4 on match or hit + 1 on mismatch — matching the previous scan byte-for-byte.

Local verification:

  • cargo test --locked -p victory-loader: 40/40 passed (36 unit + crash_log + load_probe + title_dlls)
  • cargo test --locked --release -p victory-loader --lib bench_tls_patch_64mb -- --ignored --nocapture: 2.20 ms
  • cargo clippy --locked -p victory-loader --tests -- -D warnings: 0 warnings
  • cargo xtask policy: 191 files ok
**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2956#pullrequestreview-6067487148) · **reviewed** Reviewed and verified against `main` (`63bcca43`) on Windows 11 — clean, mathematically equivalent to the byte-by-byte scan, and ready to merge (note: functionally overlaps with #188's SSE2 scanner, and based on `main` without #1192's short/empty-section guard): - Reuses `memchr = "2.8.3"` already present in `Cargo.lock` (passes `--locked` with zero new external crates). - `crates/victory-loader/src/tls.rs:78-115` searches for the 5-byte invariant tail `[0x25, 0x58, 0, 0, 0]` starting at `pos = 4`, recovers `i = hit - 4`, checks the exact same 9-byte pattern (`LOAD_LEN = 9`), and advances `pos = i + LOAD_LEN + 4` on match or `hit + 1` on mismatch — matching the previous scan byte-for-byte. **Local verification**: - `cargo test --locked -p victory-loader`: **40/40 passed** (`36` unit + `crash_log` + `load_probe` + `title_dlls`) - `cargo test --locked --release -p victory-loader --lib bench_tls_patch_64mb -- --ignored --nocapture`: **`2.20 ms`** - `cargo clippy --locked -p victory-loader --tests -- -D warnings`: 0 warnings - `cargo xtask policy`: 191 files ok
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 02:24 UTC · original · reviewed

Verified the scan equivalence: needle starts at pos>=4 so hit-4 can't underflow; the loop bound pos+5<=len preserves the old i+9<=len check; on-match pos=i+13 aligns with the next instruction's needle field, and non-match pos=hit+1 keeps overlapping-needle coverage identical to the bytewise oracle — which the test diffs byte-for-byte including the patched output. The len<LOAD_LEN early-out covers the code[pos..] slice.

**@⁠kotekompotek** on GitHub · 2026-11-26 02:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2956#pullrequestreview-6067731274) · **reviewed** Verified the scan equivalence: needle starts at pos>=4 so hit-4 can't underflow; the loop bound pos+5<=len preserves the old i+9<=len check; on-match pos=i+13 aligns with the next instruction's needle field, and non-match pos=hit+1 keeps overlapping-needle coverage identical to the bytewise oracle — which the test diffs byte-for-byte including the patched output. The len<LOAD_LEN early-out covers the code[pos..] slice.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 20:30 UTC · original

NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head 47880d3 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: memmem_patch_matches_bytewise_oracle.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 20:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2956#issuecomment-7202760925) NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head `47880d3` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `memmem_patch_matches_bytewise_oracle`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2956/head:github-bot/gh-2956'
git switch 'github-bot/gh-2956'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2956'
git switch 'github-bot/gh-2956'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2956'
git switch 'github-bot/gh-2956'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2956'
git switch 'main'
git merge --squash 'github-bot/gh-2956'
git switch 'main'
git merge --ff-only 'github-bot/gh-2956'
git switch 'main'
git merge 'github-bot/gh-2956'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2956
No description provided.