4 ms·
Zig Structs of Arrays (2024)
- Sweepi 4mo agoOT: I just spend a few minutes searching for the source of the "Not all CPU operations are created equal" slide of the linked presentation (Andrew Kelley - Practical DOD), its here: https://6it.dev/blog/infographics-operation-costs-in-cpu-clock-cycles-741 https://6it.dev/blog/infographics-operation-costs-in-cpu-clo...
- skywal_l 4mo agoYou URL seems KO, an alternative I found: https://x.com/chessMan786/status/1879092981892067383/photo/1 https://x.com/chessMan786/status/1879092981892067383/photo/1
- trymas 4mo agoSlightly related recent HN post: https://news.ycombinator.com/item?id=48382382 https://news.ycombinator.com/item?id=48382382
- Thaxll 4mo agoThis is what games do with ECS.
- hiccuphippo 4mo agoHugged to death. Mirror: https://web.archive.org/web/20260608113005/https://andreashohmann.com/zig-struct-of-arrays/ https://web.archive.org/web/20260608113005/https://andreasho...
- binaryturtle 4mo agoI'm just seeing a "410 Gone" error on the linked site (same happens to the parent URL too).
- ArneCode 4mo agoWorks for me
- binaryturtle 4mo agoStill the same. I guess it's some sort of wild anti-bot stuff basing on the user agent? /edit Yes, as confirmed with cURL, using my browser's "User Agent": 410 blocked. Using some other "User Agent" and it passes along the data. Pretty silly, IMHO.
- smallstepforman 4mo agoThe GPU loves arrays of structures AoS, since all vertex data fits in its triangle assembly cache. Once given to the GPU, the software side doesnt really care for all vertex parameters so this optimisation is pointless. Only relavent when you have instance rendering (leaves, grass) but then you only need an array of vec3’s, not the other parameters so back to normal arrays. Meanwhile, game engines need operator overloading for adding/multiplying vectors (spatial transforms, lighting, physics) and core zig design philosophy prevents operator overloading. Blind leading the blind. Disclaimer - I do professional rendering engines.
- awesan 4mo agoZig is adding native vectors including operator support, there are some recent issues/prs about this topic. The general technique of SoA is pretty useful both in games and other applications, but of course I cannot speak to the specific use-case you are describing.
- nvme0n1p1 4mo agoZig vectors force data into SIMD registers even if that would make the code slower. They're a specialty type. You should only reach for vectors if you would have used SIMD intrinsics in C for example.
- e4m2 4mo agoZig vectors do not necessarily force data into SIMD registers; a scalar implementation would work equally well. This is not just a theoretical argument, because Zig code that uses `@Vector` also has to compile for architectures that do not have SIMD instructions. That being said, the parent commenter is actually referring to other recent proposals as opposed to existing `@Vector` functionality: https://codeberg.org/ziglang/zig/issues/32032 https://codeberg.org/ziglang/zig/issues/32032 https://codeberg.org/ziglang/zig/issues/35376 https://codeberg.org/ziglang/zig/issues/35376
- nvme0n1p1 4mo ago
- nejam 4mo agoJdoemhoe
- nejam 4mo agoJfpe?
- blt 4mo agoAfter that build-up, I was hoping to see a toy implementation of a method or two for `MultiArrayList`.