Repository navigation
Reuse Metal WAR tracking hash tables - #3882
Merged
angeloskath merged 2 commits intoJul 22, 2026
Merged
Conversation
angeloskath
approved these changes
Jul 21, 2026
angeloskath
left a comment
Member
There was a problem hiding this comment.
Interesting if that makes such a difference. Can you please also provide a benchmark to showcase the 2% eg running mlx_lm.benchmark or something similar.
1 task done
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.
Proposed changes
Metal’s write-after-read tracking moves
next_inputs_andnext_outputs_into the previous sets at every barrier. This discards the old hash tables, so the next sets must rebuild their bucket lists during the following barrier epoch. This change was introduced in this PR #3630.Qwen 35B hits this path 1,056 times per decoded token. The input side alone caused 1,859 bucket-table growths per token, while output tracking followed the same allocation pattern.
This change swaps both pairs of sets instead. The existing
clear()calls remove old entries while keeping all four bucket tables for reuse. Synchronization behavior and tracked resources are unchanged.Controlled Qwen runs with input-table reuse improved throughput by about 1.9%, with identical output and unchanged peak memory. MLX’s RoPE benchmark also showed no regression. The output-table reuse applies the same optimization but was not benchmarked separately.
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes