gfx10: keep an instruction's words inline instead of in a heap vector (decode -18..-45%, translation -1..-5%) #1623
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1623
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1623"
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?
@pes7 on GitHub · 2026-11-24 19:55 UTC · original
pes7:perf/instruction-words→main· +39 −17 · 5 files · 2 commits · openEvery GFX10 instruction owns a heap vector for its one or two dwords. They fit inline - the longest instruction here is five dwords - which takes 18-45% off
decodeand 1-5% off a whole translation, with byte-identical output.Instruction::words: Vec<u32>is built withcollect()in the decoder, so every decoded instruction makes one allocation for one to five words of data, and reads them back through a pointer. #1002's counter put it at 1.17 allocations and 149 bytes per instruction - the single largest allocation source in decode.What changes
words: [u32; Instruction::MAX_WORDS]pluslen: u8, andwords()returns the slice.MAX_WORDSis 5 because that is the longest instruction the decoder produces: an MIMG with its three extra address dwords (2 + ((w >> 1) & 3)); VOP3/VOP3P with a literal is 3, everything else 2 or 1. A longer instruction is now a cleanIsaerror rather than a silent truncation.The struct does not grow:
Vecis 24 bytes,[u32; 5]+u8+ padding is 24.Call sites move from the field to the accessor (8 in
gfx10/mod.rs, 1 insp3.rs, 2 infields.rs).Measured
Bench from #1002, standalone against
mainffe310e(not stacked on the other PRs), twelve interleaved rounds per arm, best of each, nanoseconds per instruction:decodebeforeHonest about the shape:
decodeitself is 18-45% faster, but the whole translation is 1.2-5.1%, and the gain shrinks with program size - at 16 k instructions it is inside the run-to-run spread of this machine. What it buys beyond the CPU time is one allocation and one indirection per instruction gone.Applied on top of #1002 + #1033 + #1180 the same change measured 0.929-0.957 of the translation, because the per-instruction constant those three leave behind is smaller and the removed allocation is a larger share of it. Both numbers are real; this one is the one that stands alone.
Correctness
cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.-D warnings;cargo xtask policy.No game data used. Four files, +38/-16; independent of #1002, #1033, #1180 and #1556.
What it gives (to decide the merge): an instruction's words are kept inline (
[u32; 5]) instead of in a heap vector: decode -18..-45 %, translation -1..-5 % (the numbers in the description).State: MERGEABLE, CI
checkgreen, rebased onto today'smain(f3578e3).Risk: rebased for #2143 (
words().len()through the accessor); 302victory-shadertests pass.@pes7 on GitHub · 2026-11-24 22:56 UTC · original
Heads up before merging: this PR and #1180 conflict with each other in
gfx10/mod.rs. Both change theInstructionstruct and both change whatdecodeputs in it, so whichever is merged second does not apply - I checked by merging my own branches together, not just each againstmain.This branch is stacked on
perf/instruction-name(#1180) to fix that, so:wordschange alone.The resolution keeps both wins, since they are independent:
wordsis the inline[u32; MAX_WORDS]withlen(#1623) andnameis the opcode name resolved once at decode (#1180), so an instruction carries both.Verified on the stack:
cargo test --workspace --locked476 passed, 0 failed; both clippy configurations with-D warnings;cargo xtask policy. The old head was72eff75, this is13eece9(three commits: #1180's, mine, and the merge that resolves the conflict - they collapse once #1180 is inmain).@Marvisak on GitHub · 2026-11-25 03:31 UTC · original · edited 2026-11-25 22:23 UTC
Automated triage for the maintainers.
Merge candidate. Re-reviewed at
cc2a2bd, rebased onto currentmain.Instruction::wordsbecomes an inline[u32; 5]pluslen, read throughwords()(crates/victory-shader/src/gfx10/mod.rs); five is the decoder's longest instruction (MIMG,2 + ((w >> 1) & 3)), and a longer one is now anIsaerror instead of a truncation. The only new hunk is the one the second look asked for:code_table_startincrates/victory-shader/src/emit/lower.rsnow readsi.machine.words().len(). I checked the merged tree: no other read of the old field and no other construction ofInstructionremains outside the files this PR changes.On your reply: confirmed, that was the one change needed. CI:
checkpassing on this head.Generated by Claude Code
@pes7 on GitHub · 2026-11-25 16:26 UTC · original
Real corpus, same method as the note on #1002: the Xbox build's
shaders.rpf- 26 084 programs, 40 601 701 IR instructions -victory translate <shaders.rpf> --list, three binaries running at the same time on one thread each (--jobs 1) on a 32-core machine, so they share identical conditions:mainmain940d32f246c928d809fb7-1.2% is at the bottom of the -1..-5% the PR claimed on synthetic programs, which is what one would expect: the allocation it removes is one per instruction, and decode is a small part of a translation.
The output is identical to
mainon all 26 084 programs (every summary count and everyemit:/resources:line; only the(e.g. ...)examples differ, supplied by whichever thread finishes first).That the two PRs are -3.2% and -1.2% rather than overlapping noise is also a check on the method: they were measured in the same window as the control.
@Marvisak on GitHub · 2026-11-25 22:03 UTC · original
Automated triage for the maintainers, second look (a review against
main, with the PR built and tested).This is right as reviewed (an instruction's words fit inline; the tests pass). It no longer builds on
main, though: #2143, merged today, readsi.machine.words.len()incode_table_start(crates/victory-shader/src/emit/lower.rs), andwordsbecomes an accessor here. GitHub shows no conflict because the two touch different lines. Please rebase and change that call toi.machine.words().len(); with that one change the two were built and tested together.Push the change and it will be reviewed again. Thank you for the contribution.
@pes7 on GitHub · 2026-11-25 22:16 UTC · original
Rebased onto today's
mainand fixed the one thing the triage found in #2143:code_table_startreadsi.machine.words.len(), which the inline array makes a private field. It now goes through the accessor (words().len(), the same slice length), the branch is rebased (4ca9bc1->cc2a2bd), andcargo test --release -p victory-shaderpasses (302 tests, 3 ignored).No other file needed a change: the rest of the branch applies as it was.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.