[clang] [Clang][Lexer][Performance] Optimize Lexer whitespace skipping logic (PR #180819)

Thibault Monnier via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 13 02:03:18 PST 2026


Thibault-Monnier wrote:

I am not sure this is entirely true. While it _is_ certainly influenced my micro architectural details, it is by no means a "small" change. In pure -E compilation, I achieved near 2% performance improvement, which means it was probably even more when considering only the lexing part.

Furthermore, it _does_ depend on the processor, but the idea behind this change is that, for most codebases, the `isHorizontalWhitespace` call is _never_ true, which means it can basically be skipped by the branch predictor (which I assume will be the case on most modern processors), so we are simply exchanging a table lookup with a `*CurPtr == 32`. This can be proven by the `branch-misses` metrics. It is too noisy to be meaningful on the LLVM Compile Time Tracker, but using `perf stat` locally I find that it goes down. This means that:
- Branch misses goes down.
- Branching cost probably goes down as well.

Therefore, I would be surprised if this causes a regression on _any_ serious processor. 

https://github.com/llvm/llvm-project/pull/180819


More information about the cfe-commits mailing list