CMake: enable LTO in release mode
Link-Time Optimization (LTO) is a mechanism that enables the compiler to
optimize across translation unit boundaries. In particular, it enables
cross-file function inlining. This is present and mature in the majority of
contemporary compilers and switching it on has few downsides.
Some performance numbers:
┌───────┬──────────────────┬──────────────────┬──────┐
│ │ before │ after │ diff │
╞═══════╪══════════════════╪══════════════════╪══════╡
│ 1652¹ │ 17.88s │ 17.85s │ -0% │
│ │ 50.4MB peak RSS │ 50.5MB peak RSS │ +0% │
├───────┼──────────────────┼──────────────────┼──────┤
│ 1718² │ 2m21s │ 2m13s │ -6% │
│ │ 15.8MB peak RSS │ 15.9 MB peak RSS │ +1% │
├───────┼──────────────────┼──────────────────┼──────┤
│ 1864³ │ 13.26s │ 13.07s │ -1% │
│ │ 462.0MB peak RSS │ 461.8MB peak RSS │ -0% │
├───────┼──────────────────┼──────────────────┼──────┤
│ 2064⁴ │ 11m42s │ 11m30s │ -2% │
│ │ 1.26GB peak RSS │ 1.26GB peak RSS │ -0% │
├───────┼──────────────────┼──────────────────┼──────┤
│ 2095⁵ │ 2m18s │ 2m19s │ +1% │
│ │ 92.3MB peak RSS │ 92.1MB peak RSS │ -0% │
└───────┴──────────────────┴──────────────────┴──────┘
¹ The test case from https://gitlab.com/graphviz/graphviz/-/issues/1652 run as
`neato -Tsvg -o /dev/null 1652.dot`.
² swedish-flat.dot Magnus attached to
https://gitlab.com/graphviz/graphviz/-/issues/1718 run as
`circo -Tsvg -o /dev/null swedish-flag.dot`.
³ The test case from https://gitlab.com/graphviz/graphviz/-/issues/1864 run as
`twopi -Tsvg -o /dev/null 1864.dot`.
⁴ The test case from https://gitlab.com/graphviz/graphviz/-/issues/2064 run as
`dot -Gnslimit=2 -Gnslimit1=2 -Gmaxiter=5000 -Tsvg -o /dev/null 2064.dot`.
⁵ The tests/2095.dot test case from prior to minimization
(
3819821ea70fae730dd224936628ed3929b03531). Run as
`dot -Tsvg -o /dev/null 2095.dot`.