root icon indicating copy to clipboard operation
root copied to clipboard

[cxxmodules][cling] Avoid loading some unnecessary modules

Open junaire opened this issue 3 years ago • 139 comments

When we run into an unkown identifier that is a namespace, we don't really need to load its corresponding modules. Instead, we create a new module that forward declared all namespaces and always load it first. By doing so, we can avoid loading a lot of unnecessary modules.

Signed-off-by: Jun Zhang [email protected]

junaire avatar Jul 06 '22 16:07 junaire

Can one of the admins verify this patch?

phsft-bot avatar Jul 06 '22 16:07 phsft-bot

@phsft-bot build!

vgvassilev avatar Jul 06 '22 16:07 vgvassilev

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Jul 06 '22 16:07 phsft-bot

@phsft-bot build!

@Axel-Naumann, can we whitelist @junaire?

vgvassilev avatar Jul 07 '22 10:07 vgvassilev

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Jul 07 '22 10:07 phsft-bot

We passed the whole testsuite, great! I think it's ready for the review :)

junaire avatar Jul 08 '22 00:07 junaire

  • Update the commit message
  • Fix Data is not initialized We need to another build and test @vgvassilev

junaire avatar Jul 08 '22 04:07 junaire

@phsft-bot build!

vgvassilev avatar Jul 08 '22 06:07 vgvassilev

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Jul 08 '22 06:07 phsft-bot

@davidlange6, can we pick up this PR in the CXXMODULES IB and test if we bring down memory footprint?

vgvassilev avatar Jul 08 '22 10:07 vgvassilev

@phsft-bot build!

vgvassilev avatar Jul 09 '22 15:07 vgvassilev

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Jul 09 '22 15:07 phsft-bot

After b544a58, the size of modules.idx almost grows 5 times larger:

master branch:

❯ du -h lib/modules.idx
173K	lib/modules.idx

after 44434f0 (without the fix):

❯ du -h lib/modules.idx
185K	lib/modules.idx

after b544a58 (with the fix):

❯ du -h lib/modules.idx
841K	lib/modules.idx

But consider it still under 1 MB, and relatively small compared to other stuff like libCling.so (323M), I think we can afford it.

junaire avatar Jul 10 '22 01:07 junaire

Maybe only register function declarations, I can see it reduce the size from 841K to 549K...

junaire avatar Jul 10 '22 05:07 junaire

@vgvassilev - I added this patch for tonight's cmssw modules IB for a test...

davidlange6 avatar Jul 11 '22 11:07 davidlange6

@vgvassilev - I added this patch for tonight's cmssw modules IB for a test...

Thanks!

vgvassilev avatar Jul 11 '22 17:07 vgvassilev

@vgvassilev - I added this patch for tonight's cmssw modules IB for a test...

Thank you, David! BTW how can I see the test result?

junaire avatar Jul 12 '22 10:07 junaire

It wasn't an automatic test, I just have logs of memory used by an example job.

On Jul 12, 2022, at 12:14 PM, Jun Zhang @.***> wrote:

@vgvassilev - I added this patch for tonight's cmssw modules IB for a test...

Thank you, David! BTW how can I see the test result?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

davidlange6 avatar Jul 12 '22 10:07 davidlange6

@smuzaffar, can we trigger a cmssw IB for this change. I doubt there will be any breakage but let's just make sure that's the case.

vgvassilev avatar Jul 16 '22 14:07 vgvassilev

If we only care about if the identifier we look up is a top-level namespace or not, maybe we don't need to store the DeckKind info in GlobalModuleIndex, I plan to rework a little bit and only use a char to represent the state. I believe it decreases modules.idx size a little bit as well. WDYT? @vgvassilev

junaire avatar Jul 16 '22 15:07 junaire

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Jul 16 '22 16:07 phsft-bot

If we only care about if the identifier we look up is a top-level namespace or not, maybe we don't need to store the DeckKind info in GlobalModuleIndex, I plan to rework a little bit and only use a char to represent the state. I believe it decreases modules.idx size a little bit as well. WDYT? @vgvassilev

We care if the identifier is a namespace. The top namespace is just a heuristic which we use now. However, I expect to be able to avoid loading of all namespaces until another declaration is needed.

vgvassilev avatar Jul 16 '22 16:07 vgvassilev

Thanks for working on this! Let's aim to merge this PR - I have added several comments.

We might be thinking how to make the patch in clang's GlobalModuleIndex smaller or orthogonal to the existing functionality as we might be breaking some upstream use cases.

Now it decreased to 345K

❯ du -h lib/modules.idx
345K	lib/modules.idx

junaire avatar Jul 16 '22 16:07 junaire

If we only care about if the identifier we look up is a top-level namespace or not, maybe we don't need to store the DeckKind info in GlobalModuleIndex, I plan to rework a little bit and only use a char to represent the state. I believe it decreases modules.idx size a little bit as well. WDYT? @vgvassilev

We care if the identifier is a namespace. The top namespace is just a heuristic which we use now. However, I expect to be able to avoid loading of all namespaces until another declaration is needed.

OK, but this may not only need just record some flags in the GMI but also other work. For now, I think the implementation is good enough.

junaire avatar Jul 16 '22 16:07 junaire

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Jul 18 '22 07:07 phsft-bot

Build failed on mac1015/cxx17. Running on macitois21.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Jul 18 '22 09:07 phsft-bot

@phsft-bot build!

vgvassilev avatar Jul 28 '22 19:07 vgvassilev

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Jul 28 '22 19:07 phsft-bot

Build failed on ROOT-performance-centos8-multicore/cxx17. Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Jul 28 '22 19:07 phsft-bot

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Aug 17 '22 09:08 phsft-bot