Live data from Hacker News

Enum of Arrays

tigerbeetle.com

41–50 of 52 posts

Re: Enum of Arrays

#41
post #22

This thing should be a poster example of premature optimization. Sure you can squeeze a few milliseconds out in a performance critical task. Most things won't measurably benefit though, while making all handling super awkward. If your abstract domain description is fundamentally a collection of things that have a few parts each, then have your data type represent that, instead of turning it inside out for cache effec…

In what context?

You are assuming the poster is doing something like your typical IO-bound backend, and not, say, a High Performance Computing simulation on a compute cluster.

I have done this kind of optimization to go from 24 hour compute time to 6 hour compute time instead for instance -- per simulation run.

How can you say "a few milliseconds" when you know absolutely nothing about the context?

I do not consider your advice any better at all; you assume all computer code is in the same context -- it really is not. Not all code is written as backend to websites.

You could have said "keep in mind that if you service is IO-bound, these kinds of optimizations are likely a waste" or similar to make the context clear.

Re: Enum of Arrays

#42

But the author can't be bothered to tell us what language his code snippets are written in. inb4: "The concepts are language independent."

Yeah ... honestly, having an "in Zig" dropped subtly at the top would have alleviated a lot of confusion as to "why this c code looks so weird". :facepalm:

Re: Enum of Arrays

#43
post #41
post #22

This thing should be a poster example of premature optimization. Sure you can squeeze a few milliseconds out in a performance critical task. Most things won't measurably benefit though, while making all handling super awkward. If your abstract domain description is fundamentally a collection of things that have a few parts each, then have your data type represent that, instead of turning it inside out for cache effec…

In what context? You are assuming the poster is doing something like your typical IO-bound backend, and not, say, a High Performance Computing simulation on a compute cluster. I have done this kind of optimization to go from 24 hour compute time to 6 hour compute time instead for instance -- per simulation run. How can you say "a few milliseconds" when you know absolutely nothing about the context? I do not consider…

> In what context?

This is a great question for the article's author, I think! They give very little information as to when this class of optimization makes sense, and because it's much more complex to implement than the AoS -> SoA transformation in the general case when the total ordering of enums is important, either a case-study or some general heuristics as to when this transformation is worth the effort would make the article more useful and interesting.

Re: Enum of Arrays

#44

I don't get it, why wouldn't you just store tag + count instead? Am I missing something?

The article is eliding the enum's payload. A more realistic example would, I think, have each leg of the enum contain a distinct type of struct (or some other data) in addition to the tag itself, and then have each EoA factored into its own internal SoA.

Re: Enum of Arrays

#45
post #41
post #22

This thing should be a poster example of premature optimization. Sure you can squeeze a few milliseconds out in a performance critical task. Most things won't measurably benefit though, while making all handling super awkward. If your abstract domain description is fundamentally a collection of things that have a few parts each, then have your data type represent that, instead of turning it inside out for cache effec…

In what context? You are assuming the poster is doing something like your typical IO-bound backend, and not, say, a High Performance Computing simulation on a compute cluster. I have done this kind of optimization to go from 24 hour compute time to 6 hour compute time instead for instance -- per simulation run. How can you say "a few milliseconds" when you know absolutely nothing about the context? I do not consider…

> I have done this kind of optimization to go from 24 hour compute time to 6 hour compute time instead for instance -- per simulation run.

I'm sure there are workloads where this kind of optimization makes a lot of sense. But they are comparatively rare. And they are not for free, in terms of code complexity and robustness. So, for the broad masses reading HN, its a premature optimization.

> How can you say "a few milliseconds" when you know absolutely nothing about the context?

Most code that gets written is not performance critical. Programmers would generally be better advised to think about robustness, correctness and maintainability of their code than about cache effects. The world would be a better place and we'd see fewer app crashes and fewer security holes.

Re: Enum of Arrays

#46
The opposite of "struct" isn't "enum", it's "union" (or "variant"). This blog post isn't about turning an array of enums into an "enum of arrays"; it's about turning an array of unions into a union of arrays.

Which breaks down if any of your unions hold different alternatives. The "array of structs to struct of arrays" transformation, OTOH, cannot break.

It's also common to transform an "array of unions" (or "array of [pointers to] polymorphic types") into a "struct of shorter [homogeneous] arrays."

Re: Enum of Arrays

#47

The idea that arrays of structs are inherently more cache friendly and thus data-oriented-er is a bit reductive of the whole practice of data-oriented code. The point is to optimize data layout for access patterns . Putting fields of a struct into their own arrays is only actually an optimization if you're only accessing that field in-bulk. And if so, why is it even in a struct in the first place? If you use all fiel…

Indeed, a struct can also be cooked to pack down with no padding, and or be dynamically redefined with a union. Performance issues start to crop up with naive pre-fetching, and thus 100% guaranteed cache misses if the arrays are larger than L2. This is why LLM AI generated slop degrades blogs into slop delivery services. =3

> This is why LLM AI generated slop degrades blogs into slop delivery services. =3

Not sure what LLMs and AI have to do with any of this.

Re: Enum of Arrays

#48

Earlier quoted context omitted.

Indeed, a struct can also be cooked to pack down with no padding, and or be dynamically redefined with a union. Performance issues start to crop up with naive pre-fetching, and thus 100% guaranteed cache misses if the arrays are larger than L2. This is why LLM AI generated slop degrades blogs into slop delivery services. =3

> This is why LLM AI generated slop degrades blogs into slop delivery services. =3 Not sure what LLMs and AI have to do with any of this.

That is the primary problem domain, as there are a lot of folks that see well-structured nonsense as meaningful. =3

Re: Enum of Arrays

#49

Earlier quoted context omitted.

> This is why LLM AI generated slop degrades blogs into slop delivery services. =3 Not sure what LLMs and AI have to do with any of this.

That is the primary problem domain, as there are a lot of folks that see well-structured nonsense as meaningful. =3

Why do you keep putting a penis "=3" at the end of your messages?
Post reply on HN