You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
runtime: hash native_pso HashMap and avoid heap churn in plan() - #1940
Item ID: RT-NATIVE-PSO-HASHMAP-AND-PLAN-PERF (claimed in #1608 comment #7167689403).
Summary
Optimises native_pso::HashMap parsing/lookup and removes per-stage heap churn in native_pso::plan(), while adding overflow-safe bounds checks in decode_state_b() and a portable unit test suite (native_pso_plan_test).
With native_hashes.txt now carrying ~25,321 shader digests and plan() running on every native PSO creation across retail world loading, replacing the red-black tree and per-block heap allocations directly speeds up pipeline lookup and planning:
runtime/src/native_pso.h:
Added DigestHash (mixing both 64-bit halves of the 16-byte digest via a splitmix64 finaliser) and switched HashMap::map_ from std::map<Digest, ShaderRef> to std::unordered_map<Digest, ShaderRef, DigestHash> (retaining #include <map> because runtime/shims/d3d12_xs_native_pso.h relies on it transitively).
Pre-reserved map_ in HashMap::parse() using a newline count (std::count) and checked map_.find(*digest) before constructing ShaderRef strings on duplicate digests.
Replaced the per-call std::set<Digest> in record_digests() with a small-size linear deduplication path (kLinearDedupLimit = 16) that spills to std::unordered_set<Digest, DigestHash> only for large candidate lists.
Scanned bytes(block.records) directly in plan() using a stack Digest instead of allocating a temporary std::vector<Digest> + std::set<Digest> per stage block (identical semantics: duplicate digests hit the same const ShaderRef*, while two distinct matched digests still return PlanStatus::multiple_matches).
Pre-reserved hex() (32 bytes) and decode_state_b() (s.elements.reserve(count)), and rewrote the remaining-bytes checks in decode_state_b() as subtraction (b.size() - at < ...) to prevent size_t addition wrap.
Note: shares runtime/CMakeLists.txt with the open #2566; a rebase may be needed if #2566 lands first.
AI-assisted (Claude Code, Claude Opus 5.5).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item ID:
RT-NATIVE-PSO-HASHMAP-AND-PLAN-PERF(claimed in #1608 comment #7167689403).Summary
Optimises
native_pso::HashMapparsing/lookup and removes per-stage heap churn innative_pso::plan(), while adding overflow-safe bounds checks indecode_state_b()and a portable unit test suite (native_pso_plan_test).With
native_hashes.txtnow carrying ~25,321 shader digests andplan()running on every native PSO creation across retail world loading, replacing the red-black tree and per-block heap allocations directly speeds up pipeline lookup and planning:runtime/src/native_pso.h:DigestHash(mixing both 64-bit halves of the 16-byte digest via a splitmix64 finaliser) and switchedHashMap::map_fromstd::map<Digest, ShaderRef>tostd::unordered_map<Digest, ShaderRef, DigestHash>(retaining#include <map>becauseruntime/shims/d3d12_xs_native_pso.hrelies on it transitively).map_inHashMap::parse()using a newline count (std::count) and checkedmap_.find(*digest)before constructingShaderRefstrings on duplicate digests.std::set<Digest>inrecord_digests()with a small-size linear deduplication path (kLinearDedupLimit = 16) that spills tostd::unordered_set<Digest, DigestHash>only for large candidate lists.bytes(block.records)directly inplan()using a stackDigestinstead of allocating a temporarystd::vector<Digest>+std::set<Digest>per stage block (identical semantics: duplicate digests hit the sameconst ShaderRef*, while two distinct matched digests still returnPlanStatus::multiple_matches).hex()(32 bytes) anddecode_state_b()(s.elements.reserve(count)), and rewrote the remaining-bytes checks indecode_state_b()as subtraction (b.size() - at < ...) to preventsize_taddition wrap.runtime/test/native_pso_plan_test.cpp&runtime/CMakeLists.txt:native_pso_plan_test/ CTestnative_pso_plancoveringhex/parse_digest,record_digests(including >16-digest hash spill and duplicates),HashMap::parsevalidation/duplicates/conflicts, allplan()status paths (including repeated matching digest vs two distinct matching digests), anddecode_state_b().A/B Benchmark (
-O2, 25,321 synthetic catalog digests)main)HashMap::parse(25,321 lines, 2 runs)HashMap::find(per lookup, 2 runs)plan()(VS+PS, per call, 2 runs)Verification
clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror:native_pso_plan_test: PASSnative_pso_blend_test: PASSnative_pso_depth_test: PASSclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror:native_pso_plan_test: PASSclang++ -std=c++20 -O2 -Wall -Wextra -Werror:native_pso_plan_test× 3 runs: PASSpython3 -I scripts/check_no_game_data.py runtime/src/native_pso.h runtime/test/native_pso_plan_test.cpp runtime/CMakeLists.txt: PASSpython3 -I tests/test_text_write_line_endings.py: PASS (3/3)