hn.today

It's the Memory Latency, Stupid

pivotlake.io68 points16 comments
Screenshot of It's the Memory Latency, Stupid

A database query can report 100% CPU use while the processor spends much of its time stalled, waiting for data from RAM. The key bottleneck in a GROUP BY with millions of distinct values is often memory latency: a large hash table makes lookups likely to miss the CPU’s small, fast caches and fetch data from much slower DRAM. The argument is that doing more CPU work can still make a query faster if it reduces those costly memory accesses.

To test this, the author compares a straightforward aggregation against a partitioned approach on ClickBench’s 99-million-row hits dataset, with about 17 million unique UserIDs. The partitioned version hashes each key into one of 4,096 vectors, then aggregates each partition in a smaller hash table. On a single core of an AMD EPYC 9124, this extra work reduced memory-stall time from roughly 50% to 23.5% and DRAM reads from 4.5 GB to 1.5 GB; runtime fell to about 2.7-3.3 seconds, depending on the run. Pivot’s more optimized single-core implementation took about 1.85 seconds and read 954 MB, while its 16-core execution took about 172 milliseconds. The broader lesson is to optimize for data locality and cache behavior, not simply to minimize instructions.

Read on pivotlake.io16 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Shaun Thomas: Burnt Toast

Shaun Thomas: Burnt Toast

PostgreSQL’s TOAST storage made the table much smaller, and counting or scanning rows was faster than with the larger uncompressed table. But reading a field inside every toasted value required far more buffer reads, showing that TOAST can trade space savings for slower access to large values. (pgedge.com)

Jepsen: ParticleDB 1.1.4

Jepsen: ParticleDB 1.1.4

Jepsen found 96 bugs in ParticleDB versions 1.1.4 through 1.1.18.11.rc-22, including crashes, data loss, and serious transaction anomalies. Most issues were fixed, but committed writes could still disappear and serializable transactions still had anomalies; Orkes says a later release resolves the remaining problems. (jepsen.io)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.