5 ms·
I'm guessing that the author is just confusing multiple things. Andrew has been using data oriented approaches to make the self hosted compiler fast. And the a
by lucozade 4y ago
I'm guessing that the author is just confusing multiple things.
Andrew has been using data oriented approaches to make the self hosted compiler fast. And the article mentions an example where he's separated (presumably arrays of) tagged unions into distinct arrays of tags and payloads. Depending on the access pattern, this can definitely speed things up on modern CPUs.
The article then goes on to say that this is impossible in Rust, which is probably a fair statement. You may be able to get something quite close with really horrible, unsafe code but no sane person would try.
But it's blatantly untrue that you can't do this in C. I mean, C doesn't even have tagged unions so you need to code the tags explicitly if you want them. Separating them into a different array is trivial.
I guess it's possible that one could argue, say, Turing idiomatic Zig into highly optimised Zig is easier than the equivalent in C so, in practice, equivalent code is faster. Or some such. I have no idea if anyone's actually shown that quantitively though.
- LegionMammal978 4y ago> The article then goes on to say that this is impossible in Rust, which is probably a fair statement. You may be able to get something quite close with really horrible, unsafe code but no sane person would try. As it happens, a crate was just released that does exactly this, using a derive macro [0]. (I wouldn't recommend using it quite yet, though; it still has a few kinks to be worked out.) [0] https://crates.io/crates/peapod https://crates.io/crates/peapod
- pcwalton 4y agoYeah, in general macros allow for Rust to do these things just fine. I wouldn't say that it's a fair statement at all.