hsm
hsm copied to clipboard
Improve Compiletime
The last state machine benchmark run showed that runtime is very good and on par with sml and msm. Compiletime is on par with msm but a factor 20 higher than sml. Compiletime should be investigated further and the goal is to get onto the same level as sml.
Benchmark | Hsm | Sml | Msm | Statechart |
---|---|---|---|---|
Simple state machine | ||||
Complex state machine |
Since clang 9 you can analyse compile time very detailed with the cxx flag -ftime-trace
. This flag generates a json file which can be loaded into the chrome trace analyser chrome://tracing/
. In contrast to templight++ it does not only show template instantiations, but also source code include time and backend optimization.
Since hsm is header only, the compiler needs some seconds to process all the includes. The sml library provides a preprocessed header file. The script to create this header file can be found here.
Just as an inside: I'm quite interested in trying out HSM, however the compile time currently is prohibitive.
fwiw, for preprocessing and amalgamation of headers Quom is quite often used, e.g. by CPRE
@ooxi thx for considering hsm. Compile time is currently also my biggest pain point. I will definetly try quom which will save us some seconds.
If you have some more tips to reduce compile time heavily you are welcone. I was experimenting with mp11 for the hot path in dispatch table generation, but its way harder to code then using pure hana.
@ooxi I added a preprocessed header as `hsm/hsm_gen.h". Using this header reduces the compile time by 1 second.
@erikzenker that's great news! Just to make sure I understand you correctly, this reduces the compile time by one second or the compile time is reduced to one second?
@erikzenker that's great news! Just to make sure I understand you correctly, this reduces the compile time by one second or the compile time is reduced to one second?
Just by one second 😒
While adding the latest features to the library the compile time got even worse. I started to write a gist about my investigations: https://gist.github.com/erikzenker/a318fd59cdb4de87db3d659cf425cc1a#file-clang_compile_time_cookbook-md
I attached the current compile time trace which can be opened with chrome chrome://tracing
. I was able to reduce the class instantiations and pending class instantiations. But I have no idea how I can reduce the compile time for the frontend code gen and the backend.

I was able to reduce the compile time a lot by replacing the remove_duplicates
version which uses hana
by a mp11
version. The complex example compiles now in ~30 seconds instead of 77 seconds. It is still 10x slower than sml, but I think I could continue this path of replacing core components with mp11
versions. I will update the compile time benchmark result of the readme soon.
There is a compile time regression since the last investigations. See state machine benchmark here: https://github.com/erikzenker/state-machine-benchmark/pull/7/checks?check_run_id=2403853253
Looks like the regression was introduced with the release v1.4.2
It was 838a20e7cf8c9187b75fe3003c4c597cf4856ed6
There is another compile time analyzer tool that I stumbled upon: https://github.com/jrmadsen/compile-time-perf
Regarding compile time: Does it matter how you write the actions/guards? Or is it mainly the number of transitions in the transition table that eat compile time?