Loader/TLS: use memchr::memmem SIMD scan in tls::patch #2956
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2956
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2956"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@RVZO6 on GitHub · 2026-11-26 01:30 UTC · original
RVZO6:rvzo/tls-memmem-fast→main· +69 −5 · 3 files · 1 commits · openReplace the byte-by-byte
.textscan incrates/victory-loader/src/tls.rs::patchformov r64, gs:[0x58]withmemchr::memmem::Findertargeting the 5-byte[0x25, 0x58, 0, 0, 0]suffix, using the existing workspacememchrdependency.Output is bit-identical to the bytewise scanner (verified by
memmem_patch_matches_bytewise_oracleacross mixed encodings, prefixes, false-positive suffixes, and boundary offsets).Measured (
--release, median of 3 runs)bench_tls_patch_64mb(64 MiB buffer with 32,768mov r64, gs:[0x58]sites): 39.79 ms → 5.51 ms (7.22×, -86.2%)Verification
--locked, default +--tests+--features diagnosticsclippy,xtask policy, full workspace tests): RVZO6/VIctory CI run #45734072839 (green, combined Wave 7 check on63bcca4).AI-assisted: T3 Code (Antigravity, gemini-4-neon).
2da556ade6to47880d38dc@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, andmemmem_patch_matches_bytewise_oracleremains. I re-readtls::patch(crates/victory-loader/src/tls.rs): it is still equivalent to the byte-by-byte scan, and thecode.len() < LOAD_LENearly return matches the old loop bound.What's left is not a code issue. The PR adds
memchras a new dependency ofvictory-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
@RVZO6 on GitHub · 2026-11-26 06:56 UTC · original
Addressed triage feedback in
47880d3:#[ignore]bench_tls_patch_64mbbenchmark test and its comment referencing binary sizes/hit counts (docs/asset-policy.md), keepingmemmem_patch_matches_bytewise_oracle.victory-loader, both clippy profiles, andxtask policy. Not run: the title; any hardware GPU.@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 onmainwithout #1192's short/empty-section guard):memchr = "2.8.3"already present inCargo.lock(passes--lockedwith zero new external crates).crates/victory-loader/src/tls.rs:78-115searches for the 5-byte invariant tail[0x25, 0x58, 0, 0, 0]starting atpos = 4, recoversi = hit - 4, checks the exact same 9-byte pattern (LOAD_LEN = 9), and advancespos = i + LOAD_LEN + 4on match orhit + 1on mismatch — matching the previous scan byte-for-byte.Local verification:
cargo test --locked -p victory-loader: 40/40 passed (36unit +crash_log+load_probe+title_dlls)cargo test --locked --release -p victory-loader --lib bench_tls_patch_64mb -- --ignored --nocapture:2.20 mscargo clippy --locked -p victory-loader --tests -- -D warnings: 0 warningscargo xtask policy: 191 files ok@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.
@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 base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo 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.memmem_patch_matches_bytewise_oracle.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#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_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.