Open sshane opened 3 months ago
I’ll look into the build performance issue later.
Due to the inefficiency of std::regex, it often takes over 90% of compile time (e.g., 10 seconds on my laptop). Many discussions online highlight that std::regex is slow both to compile and at runtime. Aside from switching to a more efficient regex library, there are few good solutions.
Why does removing -g speed it up significantly?
Also, this only takes 3s with all the regex:
batman@workstation-shane:~/openpilot/opendbc_repo$ time g++ dbc_test.cc -g -O2
real 0m3.445s
user 0m3.187s
sys 0m0.246s
It appears just adding an empty regex in the real dbc.cc causes a 2x slowdown, and subsequent patterns take almost no extra compile time.
Why does removing -g speed it up significantly?
std::regex generates a large amount of complex template code, leading to template bloat, which causes the compiler to take more time to process. This is especially true when the -g flag is enabled to generate debug information, as the compiler needs to produce detailed debug data for all the expanded templates.
RE2 looks like a good alternative to std::regex, it's has minimal headers and relatively small lib compare to other reg lib. https://github.com/google/re2
Can we precompile the regex stuff and check it in? I think another library is not worth it (unless super small), but it might be worth having to check in a new pre-compiled header when it changes.
@deanlee interesting in checking out why some objects take so long to build?