Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Compiletime #88

Open
erikzenker opened this issue May 6, 2020 · 15 comments
Open

Improve Compiletime #88

erikzenker opened this issue May 6, 2020 · 15 comments
Labels
help wanted Extra attention is needed performance

Comments

@erikzenker
Copy link
Owner

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 erikzenker added the help wanted Extra attention is needed label May 20, 2020
@erikzenker
Copy link
Owner Author

erikzenker commented May 23, 2020

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
Copy link
Owner Author

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.

@ooxi
Copy link

ooxi commented May 30, 2020

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

@erikzenker
Copy link
Owner Author

@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
Copy link
Owner Author

erikzenker commented Jun 24, 2020

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

@ooxi
Copy link

ooxi commented Jun 24, 2020

@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
Copy link
Owner Author

@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
Copy link
Owner Author

erikzenker commented Nov 29, 2020

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
Copy link
Owner Author

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
Copy link
Owner Author

erikzenker commented Dec 20, 2020

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
Copy link
Owner Author

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
Copy link
Owner Author

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

@erikzenker
Copy link
Owner Author

It was 838a20e7cf8c9187b75fe3003c4c597cf4856ed6

@erikzenker
Copy link
Owner Author

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

@hawkeyese
Copy link

hawkeyese commented May 23, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed performance
Projects
None yet
Development

No branches or pull requests

3 participants