-
Notifications
You must be signed in to change notification settings - Fork 216
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
bg::projections::detail::epsg_to_parameters causes excessive compile times #1006
Comments
Testing on
it seems that the compile time is reasonable and stable across versions with one exception: I am closing this issue. If there is something still unclear please reopen it. |
I can confirm this issue with GCC 13.2.0, compile time is back to be very large over 30 minutes. Since this issue is recurring in GCC, it might be worth revising this part of the code. |
For info: We still use the workaround to keep compile-time to a minimum, using the approach as outlined above, Source files : https://gitlab.com/shyft-os/shyft/-/blob/master/cpp/shyft/core/epsg_fast.h But would be very happy to drop them at anytime it becomes clear that there is a stable(over some time) low-compile time solution becomes available, one way or the other. Hopefully the compilers solves the problem, otherwise there might be several similar approaches to the above that might give a solution that compiles in a few seconds. |
Hi,
First of all, thanks for this excellent library!
Intro
Just to notify about an issue that might be of interest for those using the projections part of boost geometry,
limited to the epsg projection engine.
To be clear: This is not an issue about the correctness of the code, rather practical implications regarding excessive compile times.
The function in question is the boost::geometry::projections::detail::epsg_to_parameters(), that does the job of converting an epsg code to parameters that describes the transformation.
E.g. given epsg code (an int) return back boost::geometry::srs::parameters<>.
This is realized using a static array inside the mentioned function, declarative and clear to read.
the issue
The only issue is the time that the compiler need in order to resolve the expressions in the static table,
chained call,
starting with parameters<>(projection)(param1)....(param1) // the call operator is overloaded
Compile times for pre gcc 12.1 was already high (several minutes),
but with the new gcc 12.1 it becomes > 30 minutes (33 minutes on ryzen 9 5950X series, only one core used).
On godbolt, the mininal sample below works for pre 12.1 compilers, but time-out on 12.1.
Possible solutions/workarounds.
Simplify the expressions in the table
I tried to rework the static table, trying to avoid using chained expressions,
rather use use plain vector<parameter> {}.
It was kind of promising, 10 times faster!
Looking at the data that goes into the static table, it's basically code,'numbers', strongly typed,
so moving along in a direction where the data that drives the resulting parameters are simple/fast compile-time types,
it might be possible to get down to 'zero' compile-time,
E.g. creating the parameters only when really asked for,
by means of typed constants/tuples, that are cheap during compile time.
A local test with initial approach, using the same table definitions,
reduces the compile time from 33 minutes to 3 minutes. (promising)
So it illustrates that it works, even though 3 minutes to compile a table of approx 5k rows is still excessive.
Further progress on this shows that compiling a simple POD approach,
takes only 0.8 seconds. (compared to 33 minutes gcc 12.1, or 3 minutes pre gcc 12).
So approx 2000 times faster than the current situation for gcc 12.1 (and any boost geometry version, is my guess).
I think with a little work on this approach it might be worth considering,
unless there are other more obvious solutions around that I have overlooked.
Sketches for this approach looks like:
Make the table/instantiation part of a .cpp file
If the table was created as part of the compilation of the boost library itself, instead of header-only for this part, that might work.
Maybe in combination with the speedup approach, 30 minutes is still some time, for a single file.
A variant is to control the inline/static part with a compile-time define, so that affected users can choose to compile the table-part in a separate unit (avoiding repeated compilations of the stuff that takes time)
Drawbacks with this approach is clearly that it breaks header-only, so the 'hybrid' user def constant specified approach could work, helping out the users that are affected.
The text was updated successfully, but these errors were encountered: