You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Still another array access performance issue (in debug) #15685
This is a follow-up to #13938 which was only fixed in release mode(which means I still have to rely on the workaround to be able to run my code in debug mode). The reproduction code is basically identical:
Running this in debug mode is taking 93 ms for iterating over a 32768 element array:
$ zig run test.zig
error: Time: 93325090 Sum: 536854528
Running this in a profiler, I can see that the bottleneck still is a memcpy that is called once every iteration and appears to be copying the entire array:
Expected Behavior
When applying the workaround
- sum += chunk.blocks[getIndex(i)]; // ← workaround: (&chunk.blocks)[...]+ sum += (&chunk.blocks)[getIndex(i)]; // ← workaround: (&chunk.blocks)[...]
the performance is significantly better, taking only 0.4 ms instead of 93 ms:
$ zig run test.zig
error: Time: 357398 Sum: 536854528
Activity
IntegratedQuantum commentedon Jun 6, 2023
I just updated my zig version and the problem got a lot worse.
EDIT: I updated again and it is now back to how it was originally.
Expand
This simplified example was not affected in the past:
But now it is also slow:
andrewrk commentedon Jan 24, 2024
Fix landed in 2ab7893.
Revert "Don't assume a write if an operand is not in function paramet…
andrewrk commentedon Jan 24, 2024
Fix reverted in 9d5a133.
Revert "Don't assume a write if an operand is not in function paramet…
Revert "Don't assume a write if an operand is not in function paramet…
AstGen: avoid intermediate loads during field/array access
AstGen: avoid intermediate loads during field/array access
AstGen: avoid intermediate loads during field/array access
IntegratedQuantum commentedon Sep 21, 2025
fixed by #25154