mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:55:52 +01:00
[PR #1940] runtime: hash native_pso HashMap and avoid heap churn in plan() #1948
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1948
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1940
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:perf/rt-native-pso-hashmap-and-plan📝 Commits (1)
b8c59d7runtime: hash native_pso HashMap and avoid heap churn in plan()📊 Changes
3 files changed (+259 additions, -10 deletions)
View changed files
📝
runtime/CMakeLists.txt(+2 -0)📝
runtime/src/native_pso.h(+47 -10)➕
runtime/test/native_pso_plan_test.cpp(+210 -0)📄 Description
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)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.