enh: reduce binary size across all libraries #5292#5297
Conversation
Binary Size Comparison: 1.14.2 vs main vs fix branchStripped library sizes in bytes. "fix" = code changes only (default visibility). macOS arm64 (Apple Clang, RelWithDebInfo)
Linux x86_64 (GCC, RelWithDebInfo)
Note: on Linux with default visibility, GCC already deduplicates weak template symbols Changes Applied
|
|
I would like to see some benchmarks on intToStr. That function was manually written for a reason (used often in Var) to be faster than standard implementations |
Move = default constructors/destructors from headers to .cpp files for 42 non-template classes across Util (22), Prometheus (14), ActiveRecord (1), MongoDB (3), Net (1), and Redis (2) to eliminate template bloat from implicit instantiations in every translation unit. Add extern template declarations for BasicEvent types used by AbstractConfiguration to prevent duplicate instantiations across Util's 11 Configuration subclasses.
aleks-f
left a comment
There was a problem hiding this comment.
intToStr seems to be mostly pessimization. benchmark code here
Aggregate (58 cases across 4 types)
| Metric | Value |
|---|---|
| Total OLD | 1933.22 ms |
| Total NEW | 2442.94 ms |
| Delta | +509.72 ms (+26.4%) |
| NEW faster | 8 cases |
| OLD faster | 49 cases |
| ~Same | 1 case |
| Best NEW gain | -53.2% (uint64/int64_max) |
| Worst NEW loss | +168.0% (int/zero) |
Per-type breakdown
| Type | OLD | NEW | Change |
|---|---|---|---|
| int | 480.09 ms | 687.61 ms | +43.2% |
| uint | 413.37 ms | 525.80 ms | +27.2% |
| int64 | 575.95 ms | 689.48 ms | +19.7% |
| uint64 | 463.80 ms | 540.05 ms | +16.4% |
|
Here is an optimized version of the old
|
|
I will remove numeric parser/formatter changes from this PR. New PR is open for that: #5301. |
macOS: add -Wl,-dead_strip for non-Debug builds (Apple linker handles it natively on Mach-O atoms). All platforms: when CMAKE_CXX_VISIBILITY_PRESET=hidden is set, enable -ffunction-sections -fdata-sections and linker gc for non-Debug builds. Use generator expressions for proper multi-config generator support. ICF (--icf=safe) is enabled on non-Apple platforms when gold or lld is detected.
b2c8f25 to
1bb1c47
Compare
…n of copy constructor and assignment ('Rule of Two')
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Potential fix for code scanning alert no. 118: Inconsistent definition of copy constructor and assignment ('Rule of Two')
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
ab2087a to
04fb9a7
Compare
* enh: move defaulted constructors/destructors out-of-line #5292 Move = default constructors/destructors from headers to .cpp files for 42 non-template classes across Util (22), Prometheus (14), ActiveRecord (1), MongoDB (3), Net (1), and Redis (2) to eliminate template bloat from implicit instantiations in every translation unit. Add extern template declarations for BasicEvent types used by AbstractConfiguration to prevent duplicate instantiations across Util's 11 Configuration subclasses. * enh(cmake): add dead-code stripping and visibility-aware gc-sections macOS: add -Wl,-dead_strip for non-Debug builds (Apple linker handles it natively on Mach-O atoms). All platforms: when CMAKE_CXX_VISIBILITY_PRESET=hidden is set, enable -ffunction-sections -fdata-sections and linker gc for non-Debug builds. Use generator expressions for proper multi-config generator support. ICF (--icf=safe) is enabled on non-Apple platforms when gold or lld is detected. * Potential fix for code scanning alert no. 118: Inconsistent definition of copy constructor and assignment ('Rule of Two') Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Potential fix for code scanning alert no. 118: Inconsistent definition of copy constructor and assignment ('Rule of Two') Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Summary
= defaultconstructors/destructors from headers to .cpp files for 42 non-template classes across Util, Prometheus, ActiveRecord, MongoDB, Net, and Redisextern templatedeclarations forBasicEventtypes used byAbstractConfiguration-Wl,-dead_stripon macOS and visibility-aware-ffunction-sections/gc-sectionsBinary Size (stripped, default options, RelWithDebInfo)
macOS arm64 (Apple Clang)
Linux x86_64 (GCC)
On Linux with default visibility, GCC already deduplicates weak template symbols effectively. The Util savings (-65 KB) come from the BasicEvent
extern templatedeclarations eliminating duplicate instantiations across 11 Configuration subclasses.Closes #5292
Test plan