Repository navigation
Conversation
`ResourceManager` kept shaders, pipelines, passes and buffers in a `HashMap<usize, _>` with the standard library's SipHash, so every `apply_pipeline`, `apply_bindings`, `buffer_update` and `draw` hashed the ids it looked up. Ids are handed out in order and never reused, so they can index a `Vec` instead, as the Metal backend's resources and the GL textures already do. A deleted resource leaves its slot empty, so using its id still panics rather than reaching another resource. In the web build, throttled 4× in Chrome, with 200 draw calls a frame, the hashing took 0.16 ms of the frame and the lookups 0.2 ms; neither shows in a profile now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
ResourceManagerkeeps the GL backend's shaders, pipelines, passes and buffers in aHashMap<usize, _>with the standard library's hasher, SipHash. Everyapply_pipeline,apply_bindings,buffer_updateanddrawlooks resources up there, so each draw call hashes several ids. In a web build of a macroquad game (CHOMP) drawing about 200 draw calls a frame, with Chrome's CPU throttled 4×,RandomState::hash_onetook 0.16 ms of a frame and theIndeximpls around it 0.2 ms more.Change
Ids are handed out in order and never reused, so they index a
Vec<Option<T>>instead, as the Metal backend's resources and the GL backend's textures already do with aVec.removetakes the resource out and leaves its slot empty, so a deleted resource's id still panics when it's used, rather than reaching another resource.Verification
hash_oneandResourceManager'sIndexno longer show in a CPU profile of the frame.cargo buildhas no new warnings, natively or forwasm32-unknown-unknown.🤖 Generated with Claude Code