RagnarGrootKoerkamp / BAPCtools

Tools for developing ICPC-style programming contest problems.
GNU General Public License v3.0
48 stars 18 forks source link

Precompiled `validation.h` #201

Open mpsijm opened 2 years ago

mpsijm commented 2 years ago

From a discussion with @RagnarGrootKoerkamp on Slack.

The compilation of validation.h starts getting slightly slow. Because this file doesn't regularly change, we can reduce the compile time for the validators by using precompiled headers: https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html

These precompiled headers can probably be stored in /tmp for each problem. If every problem uses a symlink to a shared validation.h, we might even be able to generate one precompiled header file for all these problems, but will probably be a bit messy.

mpsijm commented 4 months ago

I tried this a few days back. On my machine, it reduced the compilation time of a simple input validator (basically only v.read_integer and v.newline) from 1.7–1.9 seconds down to 1.2–1.4 seconds. I don't think this reduction in compile time is large enough to start going through the trouble of implementing this in BAPCtools.

A different idea (thanks to some discussion with more C++-savvy people) could be to rewrite validation.h as a .cpp file, and only include the interfaces of the validators in the header file. We could then try to dynamically link this new validation.cpp to the validators in BAPCtools. DOMjudge doesn't need to know about any of that, since it will just call g++ with all .cpp files combined in one go. But this requires a bit more time to experiment with :stuck_out_tongue:

RagnarGrootKoerkamp commented 4 months ago

Hmm bummer that precompiled headers only make such a small difference. Dynamic linking does sound like a solution that would work but indeed also not very straightforward.

Maybe we could investigate which part of compilation is slow and speed that up somehow. We use templates for integer vs floating point input but instantiating things twice shouldn't be too bad.

Another thing to try could be to just lower the optimization level?