mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-24 05:40:15 +00:00
Extract the tight per-byte parsing loop from TerminalParser.step into a separate noinline function (parseAll). This eliminates a ~20% benchmark regression that appeared after the highway vendor changes despite zero changes to the parser source code. The root cause: the parser benchmark processes 50 MB of input through a byte-at-a-time DFA loop that is highly sensitive to instruction cache-line placement on Apple Silicon. The M-series cores fetch aligned 16-byte blocks; when the loop head lands near the end of a 64-byte cache line (offset 60), only one instruction fits in the first fetch versus four when aligned to offset 48. This causes ~29% more cycles for identical instruction counts. Previously the loop was inlined into the large step() function, so any code change anywhere in the binary (like the highway vendor restructuring) could shift the loop across a cache-line boundary. By making parseAll noinline, the loop gets its own function placement that is stable regardless of surrounding code changes.