hsm icon indicating copy to clipboard operation
hsm copied to clipboard

Improve Compiletime

Open erikzenker opened this issue 4 years ago • 15 comments

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
10.010 s
0.786 s
5.380 s
1.480 s
Complex state machine
77.120 s
3.130 s
26.820 s
5.190 s

erikzenker avatar May 06 '20 20:05 erikzenker

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.

erikzenker avatar May 23 '20 08:05 erikzenker

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.

erikzenker avatar May 23 '20 08:05 erikzenker

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 avatar May 30 '20 09:05 ooxi

@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.

erikzenker avatar Jun 01 '20 08:06 erikzenker

@ooxi I added a preprocessed header as `hsm/hsm_gen.h". Using this header reduces the compile time by 1 second.

erikzenker avatar Jun 24 '20 12:06 erikzenker

@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?

ooxi avatar Jun 24 '20 18:06 ooxi

@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 😒

erikzenker avatar Jun 25 '20 07:06 erikzenker

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

erikzenker avatar Nov 29 '20 13:11 erikzenker

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.

hsm

erikzenker avatar Dec 12 '20 12:12 erikzenker

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.

erikzenker avatar Dec 20 '20 11:12 erikzenker

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

erikzenker avatar Apr 21 '21 20:04 erikzenker

Looks like the regression was introduced with the release v1.4.2

erikzenker avatar Apr 21 '21 21:04 erikzenker

It was 838a20e7cf8c9187b75fe3003c4c597cf4856ed6

erikzenker avatar Apr 21 '21 21:04 erikzenker

There is another compile time analyzer tool that I stumbled upon: https://github.com/jrmadsen/compile-time-perf

erikzenker avatar Apr 24 '21 15:04 erikzenker

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?

hawkeyese avatar May 23 '23 12:05 hawkeyese