Skip to content

Reuse Metal WAR tracking hash tables - #3882

Merged
angeloskath merged 2 commits into
ml-explore:mainfrom
neilmehta24:neil/reuse-metal-war-tracking
Jul 22, 2026
Merged

angeloskath merged 2 commits into
ml-explore:mainfrom
neilmehta24:neil/reuse-metal-war-tracking

Conversation

@neilmehta24

Copy link
Copy Markdown
Contributor

Proposed changes

Metal’s write-after-read tracking moves next_inputs_ and next_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 x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@angeloskath angeloskath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@angeloskath
angeloskath merged commit 291e909 into ml-explore:main Jul 22, 2026
28 checks passed
@BrewTestBot BrewTestBot mentioned this pull request Aug 18, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants