logoalt Hacker News

PGO or not PGO this is the dilemma. Step 2

12 points • by hnp9j9qtda • last Wednesday at 4:33 PM • 1 comment • view on HN

Comments

gopalv • today at 10:28 PM

> A switch statement with many cases can be compiled as a jump table (fast, O(1), but requires a full table load and indirect jump) or as a cascade of compares (slower per-case but better branch prediction if one case dominates).

Switch case is the workhorse of a lexer, parser and execution engine. Lots of them over enums.

This was all mis-optimized for years thanks to Spectre/Meltdown changing how the actual runtime of pre-fetch and speculation used to work.

All my work on CGOTO was made irrelevant by the CPU advances, only to become relevant again when fetch speculation got nerfed.

The indirect call scenario is a bit more interesting, because the JVM has an amazing paper about interface dispatch caches [1] on how to do it runtime instead of compile time.

The PGO is still useful, but not unless you can predict the workload you're going to have - Benchmarketing with a TPC benchmark is a good situation for it.

If you have consistent hardware, tuning an OLTP system for the hardware is much more interesting. Going back in the memory hole, Yahoo used to have a Jeremy Cole build of Mysql which was specially optimized for the raid disk layout that was in production (ZFS came by to fix those issues directly).

[1] - https://dl.acm.org/doi/10.1145/504311.504291