TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #25803 6
How I optimized clang for 1.73x-1.91x performance boost over apt clang

I wanted to have fast test and release builds, so I decided to "upgrade" my compiler.

What I used:

Musl Libc
LLVM libc overlay
Mimalloc
Thin LTO
PGO
Bolt via perf2bolt
Optimization flags like: -march -O3 -DNDEBUG -fno-semantic-interposition -fno-plt -fno-pie
No exceptions no RTTI

I tested the build speed with hyperfine with 2 test cases, one is sqlite.c the other is tu including eigen.

|Workload|Build mode|Optimized Clang speedup|Compile-time reduction|
|:-|:-|:-|:-|
|Eigen, C++23|-O0|1.69×|40.8%|
|Eigen, C++23|-O0 -g3 -fno-omit-frame-pointer|1.72×|41.9%|
|Eigen, C++23|-O3 -DNDEBUG|1.73×|42.2%|
|SQLite amalgamation|-O0|1.74×|42.5%|
|SQLite amalgamation|-O0 -g3 -fno-omit-frame-pointer|1.89×|47.1%|
|SQLite amalgamation|-O3 -DNDEBUG|1.73×|42.2%|

In case anyone is wondering, it also outperformed LLVM release binaries, by about %13 to %15 for each case, but having more performance than the system compiler is more cool so I'm not giving the table for that.

It is also very awesome to have a compiler not depend on glibc. If no errors arise, I'll probably never update my compiler for 2 years at least. As my build is portable(no march native just v3)

I'm planning on moving to cachyOS or any other optimized linux distro next, to finalise my build enviroment. I'm currently on Ubuntu.

https://redd.it/1wb2cq3
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
More from @r_cpp
  1. Oct 7, 2026New to c++ Hello everybody,im new to cpp,and want to learn it,i have some knowledge with C…
  2. Oct 7, 2026Optimizing the Compressed Log Pipeline: https://github.com/Tencent/BqLog/blob/main/docs/Ar…
  3. Oct 7, 2026BqLog 2.6.0: a C++ logging library running on 30M+ devices daily, benchmarked against quil…
  4. Oct 7, 2026BqLog 2.6.0: a C++ logging library running on 30M+ devices daily, benchmarked against quil…
  5. Oct 7, 2026LearnCPP taking 2.5 Go of RAM It's crazy that with the number of adds on the website, lear…
  6. Oct 7, 2026A faster way to convert a timestamp ➜ Hour, Min, Sec https://www.benjoffe.com/fast-time-of…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →