Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's also notable that video games are programs that run for hours and iterate over large sets of very similar entities at 60 frames or more per second repeatedly and often do very similar operations on each of the entities.

That also means that "just do an array of flat records" is a very sane default even if it seems brutish at first.

 help



I would like to add that Braid is not a normal video game.

To me, it is a piece of art. It contains so many mind-bending mechanics that I think it is a real possibility that you could have worked on some of that stuff for years, making it unlikely to ship at all.

So, in addition to the performance requirements of a video game, Jonathan also had to find ways to implement all those fancy mechanics.


I think when he said "just do an array of flat records" he meant as opposed to record of arrays (i.e. row oriented vs column oriented), as opposed to fancy data structures which I think you're assuming he was implying. Separate arrays for each data member are common in game engines exactly because they're good for iterating over, which as you said is common.

That's also great for letting the compiler unlock auto-vectorization opportunities without delving into the world of manual SIMD.

Even storing something simple such as an array of complex numbers as a structure of arrays (SoA) rather than an array of structures (AoS) can unlock a lot of optimizations. For example, less permutes/shuffles and more arithmetic instructions.

Depending on how many fields you actually need when you iterate over the data, you prevent cache pollution as well.


Jonathan Blow's own unreleased Jai programming language has a feature to make it trivial to switch between array-of-structs and struct-of-arrays.

From a quick search, it seems HackerNews's own jcelerier has put together a C++ library for doing this. https://github.com/celtera/ahsohtoa


Zig also makes this trivial

I believe you. Can you provide a simple example? I would be helpful for me to understand.

I haven't watched his videos on his language for ages, but this was a big thing he wanted in his language: being able to swap between array-of-structs and struct-of-array quickly and easily.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: