First of all, I hope this an appropriate category, as it isn’t a showcase of a project, but please tell me if I’m wrong.
Recently came across this video and I tried my best at implementing an HTML Parser (7.2 KB) that follows data oriented design.
The parser itself is really basic, it follows this tutorial.
I tried to implement everything from scratch, I’m not using std.MultiArrayList and everything should be working fine, but I would like some feedback on this piece of code as it is my first attempt with this programming paradigm and it turned out to be a bit difficult as you can see by my comments :')
This looks like a decent implementation. One thing that stood out to me is the use of ?Index. Since Index is a u32 and uses every possible bit pattern, the optional can’t fold null into a spare value, so it instead carries an extra tag word - making each slot being 8 bytes instead of 4. If you define a sentinel like pub const none: Index = std.math.maxInt(Index); and use that in place of null (dropping the optionals), you actually halve the memory on those arrays and get better cache behavior, which fits the data-oriented layout nicely!