Skip to content

Include cleanup: reduce header bloat#60490

Draft
MaxKellermann wants to merge 106 commits intoceph:mainfrom
MaxKellermann:includes2
Draft

Include cleanup: reduce header bloat#60490
MaxKellermann wants to merge 106 commits intoceph:mainfrom
MaxKellermann:includes2

Conversation

@MaxKellermann
Copy link
Member

@MaxKellermann MaxKellermann commented Oct 25, 2024

This is a continuation of #60253 (and contains many of its commits). It is a demonstration of what can be done do reduce header bloat.
Ceph build times are painfully slow and each compilation unit takes about 2 GB RAM, which means parallel builds require excessive amounts of CPU and RAM. This is because the header dependency tree is very large.
This draft PR shows a few ideas how to improve this:

  • include only headers that are needed
  • split headers so includers can decide what parts they need
  • un-inline functions/methods so their dependencies don't need to be included in the public header and the compiler doesn't need to generate code in each compilation unit that includes the header

Prior to this PR a clean build of ceph-mds:

3657.90user 222.19system 2:46.14elapsed 2335%CPU (0avgtext+0avgdata 3838844maxresident)k
0inputs+0outputs (24major+81216038minor)pagefaults 0swaps

 Performance counter stats for 'time ninja -C build/debug ceph-mds':

      3,891,960.89 msec task-clock:u                     #   23.424 CPUs utilized             
                 0      context-switches:u               #    0.000 /sec                      
                 0      cpu-migrations:u                 #    0.000 /sec                      
        81,140,096      page-faults:u                    #   20.848 K/sec                     
 9,183,874,937,949      cycles:u                         #    2.360 GHz                       
 9,098,969,848,371      instructions:u                   #    0.99  insn per cycle            
 2,021,603,305,694      branches:u                       #  519.431 M/sec                     
    53,365,675,475      branch-misses:u                  #    2.64% of all branches           

     166.151033259 seconds time elapsed

    3657.906470000 seconds user
     222.190450000 seconds sys

After this PR:

2621.21user 152.68system 2:05.10elapsed 2217%CPU (0avgtext+0avgdata 3271296maxresident)k
0inputs+0outputs (0major+56495236minor)pagefaults 0swaps

 Performance counter stats for 'time ninja -C build/debug -k50 ceph-mds':

      2,784,514.32 msec task-clock:u                     #   22.258 CPUs utilized             
                 0      context-switches:u               #    0.000 /sec                      
                 0      cpu-migrations:u                 #    0.000 /sec                      
        56,476,974      page-faults:u                    #   20.283 K/sec                     
 6,628,349,851,908      cycles:u                         #    2.380 GHz                       
 6,567,858,023,127      instructions:u                   #    0.99  insn per cycle            
 1,452,547,427,587      branches:u                       #  521.652 M/sec                     
    41,054,543,018      branch-misses:u                  #    2.83% of all branches           

     125.103906411 seconds time elapsed

    2621.212510000 seconds user
     152.683572000 seconds sys

This is a speedup of 28%, and much more can be done (still a lot of header bloat, and type erasure might also help a lot).

Note that this is a quick'n'dirty draft PR. Only ceph-mds builds and all other executables will fail, some due to pre-existing bugs because includes were missing, others because I didn't adapt to splitted headers yet.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Downgrade <iostream> to <iosfwd>.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
To reduce header dependencies and compile times.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants