Hacker News new | past | comments | ask | show | jobs | submit

It's the memory latency, stupid

https://pivotlake.io/blog/its-the-memory-latency-stupid/
I work with another team at work that uses lots of message passing, C++ virtual methods in deeply nested class hierarchies, large DOMs and off-the-shelf C++ STL containers... on a STM32MP1, which has an in-order Cortex-A7 and a pittance of cache.

On the other hand, in my team I wrote my custom C++ STL containers that allocate inline, SAX-style processing libraries and an object pool with links that use index+generations like 2000s video games... on a STM32H5 with less than a megabyte of RAM.

Mechanical sympathy feels like a lost art to people I demonstrate it to... and I had to demonstrate to the first team with benchmark numbers that I would not be the bottleneck between us by orders of magnitudes.

I’ve had code review pushback against reorganizing data structures to be more cache-friendly on the grounds that it was “premature optimization” even though I pre-emotively justified the decision with benchmark results indicating that the performance difference was large and business relevant, and addressed a real performance bottleneck that I observed during testing.

This was on a team and at a time where Clean Code was very popular. I somewhat wonder if the problem is that, in the 2010s, many people became convinced that certain aesthetic standards were both objectively, provably correct, and more important than anything else.

loading story #50320844
loading story #50320270
loading story #50321104
loading story #50320754
loading story #50319988
loading story #50320733
I work in the games industry with exceptionally skilled system programmers that can do that too. They're getting on in age, and there's fewer programmers in the younger generations that are interested in any of it. Technology is sadly increasingly homogenising around Unreal Engine 5
loading story #50319658
loading story #50321457
I recently spent three weeks paring down a piece of software until it could run entirely in the L1 cache of the processor it was running on. The performance was - to put it mildly - impressive. And this was 1970's technology running on a modern CPU. This stuff can do miracles if you use it right.
Someone asked me why Zig programmers seem to genuinely enjoy passing the allocator around as an argument. I didn’t have a good answer at the time, but I think I do now, thanks to your comment - feeling the “weight” of allocations is an example of mechanical sympathy, and having to pass around and use an allocator explicitly makes your code-effort more closely resemble the chip-effort it is asking for.
loading story #50322953
If it has a pittance of cache, then mechanical sympathy might not mean cache-friendliness. Linked lists were mechanically sympathetic on uncached systems - it cost the same to access any byte of memory, so you might as well go directly to the one you wanted.
loading story #50320757
loading story #50320546
> mechanical sympathy feels like a lost art

Programs should express the solution, not the problem.

loading story #50323908
loading story #50323526
I feel like the solution presented is just a clustered hashmap or “locality sensitive” if you’d like it.

Still not orders of magnitude better.

Uh, isn't this just radix-partitioned aggregation? Hierarchical (fixed two level) aggregation is old. What's novel here?

Microcosm of Pivot itself I guess. I just don't get why this project exists when DuckDB and Clickhouse both exist.

From the article: "To do this, we'll use a method called radix partitioning."

I don't think they were claiming it was novel. Seemed just like an article explaining a performance optimization

I didn't get the sense that this was the end-all, just a relatively simple way to show how much impact cache-friendly data structures can have for somewhat little effort over the naive solution and give readers a sense for how to think through the problem.
{"dead":true,"deleted":true,"id":50321731,"parent":50318720,"time":1793494152,"type":"comment"}
Shout out to the author, it seems coherent.

I like flamegraphs

I know folks use perf to help generate them

But in the future, now that Llm is here, get and agent to check assembly, PMUs and also see what you’re doing in assembly.

My 2c and happy coding to everyone :)