[SERVER-44038] On posix, SConstruct forces debug symbols with no optimization Created: 16/Oct/19 Updated: 27/Oct/23 Resolved: 22/Oct/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Build |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | James P. Harvey | Assignee: | Andrew Morrow (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Sprint: | Dev Platform 2019-11-04 |
| Participants: |
| Description |
|
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. |
| Comments |
| Comment by Andrew Morrow (Inactive) [ 21/Oct/19 ] |
|
We always generate debug information because it is a critical part of our build and release process. We retain the debug information so that when users report crashes using our prebuilt binaries, we can obtain detailed symbol and line information, or even load up core files along with the debug information and have access to local variables and function parameters in the debugger. Since we always want the debug info, we do not provide an option to disable it. While it is true that optimization sometimes interferes with debugging, it is still better to have the debug info than not have it at all. Regarding the specific flags:
For now, if you don't want to retain the debug information, you can simply stack in a patch to edit the SConscript file and remove -ggdb. Finally, we are actively working on refactoring the build process such that debug information is handled in a way that will make it both less costly and easier to manage for packagers. As I don't think we are likely to make any immediate changes, I plan to close this as "works as designed", but please reach out if there is anything additional I can help with. |
| Comment by James P. Harvey [ 16/Oct/19 ] |
|
In my original report, I am completely mistaken regarding optimization - but NOT the debug symbol generation, and space and time to build. I'm used to choosing debug symbols without optimization or no symbols with optimization. I always set up my own build systems so debug symbols and optimization are mutually exclusive. (mongodb's SConstruct attempts to make these mutually exclusive as well, but doesn't achieve this with posix because it then always includes `-ggdb` – or `-g` on emscripten.) It finally hit me that I might not have been able to enable optimization, because it might already be on. Looking at the compilation processes running, I do see by default, it's using "-ggdb -O2". So, by default, it's generating debug symbols with an optimized build. So, this winds up building an optimized binary of equal size either way, as long as it's stripped in the end. It just takes a much less efficient way to get there, and of course harms any attempts at using the debug symbols before stripping, because of the optimizations. |
| Comment by Danny Hatcher (Inactive) [ 16/Oct/19 ] |
|
Thanks for opening this. I've passed to the appropriate team. |
| Comment by James P. Harvey [ 16/Oct/19 ] |
|
Typo in original post, optimization flag should have read `-O2`. (Don't seem to have edit permission to original post, only comments.)
|