-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Build
-
None
-
ALL
-
Dev Platform 2019-11-04
Reported by Arch user lsr, mongodb 4.2.0::SConstruct::1861 always forces debug symbol generation, specifically `-ggdb` unless on emscripten, then `-g`.
Is there some reason for this?
As is, building mongodb core, and building and running unittests, dbtest, integration_tests_replset, and integration_tests_standalone takes 70 minutes and 259GB on my system. (32 cores, 64GB RAM, Samsung 970 EVO.) For some other users, it can take much longer, one user reports 18 hours.
mongod compiles to 2,340,273,376 bytes (2.3GB). By default, Arch's packaging system strips binaries reducing it to 59,100,328 bytes (59MB.)
Removing this line (1861) to prevent debug symbol generation reduces the time to 44 minutes and only 12GB! Only takes 63% of the time and 5% of the space!
mongod compiles to 70,874,120 bytes (71MB), and after stripping 59,100,328 bytes (59MB.) So, the stripped binary is the same exact size, and no optimization has been used. Only building has been made faster and less wasteful.
I looked through SConstruct more, and saw the `--release`option, which Arch hasn't used, at least lately. But, adding it did nothing. All it does is set `releaseBuild` on line 955 and is examined in several print/exit error conditions. The option doesn't prevent debug symbol generation, and it doesn't affect optimization level.
I also saw and tried the options `-dbg=off --opt=on`, but no change.
I worked a bit on trying to enable optimization. Lines 1904-1909 set optimization levels in `CCFLAGS`, but not `CXXFLAGS`. Manually setting `debugBuild = False` `optBuild = True` and `optBuildForSize = False` at line 970, and `CCFLAGS` is updated to include `-02`, but since `CXXFLAGS` isn't, it still compiles and strips to the same exact sizes as with line 1861 deleted.
Adding a line after where `optBuild and not optBuildForSize` appends `CCFLAGS` with `-Os` to also append it to `CXXFLAGS`, and it still compiles and strips to the same exact size, so even that doesn't actually use optimization.
I assume forcing debug symbols is a mistake, one that looks like it's been around since at least 4.0.6, when I started packaging mongodb, but probably quite a bit longer.
I notice link time optimization is mentioned as being experimental, except on MSVC. Is compiling with C++ optimization deliberately being avoided, or should this be fixed?
I'll also mention nowhere in the mongodb compilation documentation does it give a user or distribution packager instructions on giving any arguments to make a release build, without debug symbols, and with optimization. https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source and https://github.com/mongodb/mongo/blob/master/docs/building.md ... Not that there's a way to do this at the moment, at least on posix with gcc, but once there is, the documentation should be added if the default is going to be an unoptimized debug build.