Repository navigation
perf(shader): cut hot-path overhead in recompile cache lookups - #218
slick-daddy wants to merge 3 commits into
Conversation
|
Could you measure the speed before and after optimization? The changes seem logical to me, but I need to check. |
|
Sure. Here are the results run by AI. Windows 11, MSVC 19.44 x64, /O2, /std:c++20, 200k iterations after warmup.
Verdict per commit
Why
|
|
Yes, let's remove the changes that caused the slowdown and keep the ones that gave the acceleration. And after that, it is advisable to take measurements again, just in case. |
bce78b9 to
a0b60e4
Compare
|
Following up on boykopovar's note: since #415 merged, this conflicts in |
a0b60e4 to
eaf02e3
Compare
|
Thanks for removing the comments. The last commit ( |
e550bbc to
4e47af1
Compare
|
Done. |
|
Thanks for dropping it and for the new numbers. I checked what's left. There's one problem with the two-dwords-per-round A single bit-31 flip changes only hash bit 63. A rotate after the multiply, Minor: the table in the description still lists the |
|
Fixed in You were right, and the effect is stronger than a cancellation risk: a multiply only carries upward, so the low 32 bits of the hash never saw the odd dword at all. Flipping bit 31 of any odd dword left the low half bit-identical, and the pairs I found cancel outright. Took the rotate, but only on the packed rounds. Putting it in the shared
|
ced75cb to
77d6d68
Compare
What
Two behaviour-preserving changes to the recompile cache, which is rebuilt on every dispatch and draw. Cache-key strings are packed eight bytes per word instead of one word per byte, and the key vectors reserve their working size up front so repeated builds stop regrowing. materializeMemoized records whether it hit in a flag rather than looking memoIndex up a second time to decide whether to insert.
snapshotHash is main's one-dword-per-round hash (the packed two-dwords-per-round variants are dropped: any full-width round input lets the next input cancel a state difference, and the rotl variant collided deterministically on adjacent-dword bit flips). snapshotHash is exposed for tests, with a regression test pinning top-bit coverage per snapshot location plus the reported cancelling pair.
The key-layout change alters the bytes written into the on-disk shader cache key, but SourceVersion hashes CacheKey.hpp, so this PR invalidates existing cache entries either way.
Tested
Key numbers carried over from the prior harness run (key code unchanged since, comments only); the snapshotHash rows are gone with the revert.
Windows 11, Release, MinGW-w64 GCC 15.2.0 (WinLibs x86_64-ucrt-posix-seh, 15.2.0posix-14.0.0-ucrt-r7) - the toolchain and configuration the CI Windows job uses.
memoIndex: one hash lookup saved (~10 ns), below that rig's noise floor; same three outcomes as main in all cases.
No local toolchain in this environment (no cmake/ninja/compilers), so agc_shader_memory_tests was not run locally; a Python FNV model confirmed the reported pair is distinct on the restored hash and collides on the dropped rotl variant. CI conventions and report jobs pass; linux/windows builds pending.
Not tested on Linux locally, and no game title or homebrew was run.
Checklist