Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cxxmodules][cling] Avoid loading some unnecessary modules #10910

Closed
wants to merge 5 commits into from
Closed

[cxxmodules][cling] Avoid loading some unnecessary modules #10910

wants to merge 5 commits into from

Conversation

junaire
Copy link
Contributor

@junaire junaire commented Jul 6, 2022

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 jun@junz.org

@phsft-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@vgvassilev
Copy link
Member

@phsft-bot build!

@phsft-bot
Copy link
Collaborator

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

@vgvassilev
Copy link
Member

@phsft-bot build!

@Axel-Naumann, can we whitelist @junaire?

@phsft-bot
Copy link
Collaborator

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

@junaire junaire changed the title [WIP] [dont-merge]Initial work of enhancing GlobalModuleIndex [cxxmodules][cling] Stop loading some unnecessary modules Jul 8, 2022
@junaire junaire changed the title [cxxmodules][cling] Stop loading some unnecessary modules [cxxmodules][cling] Avoid loading some unnecessary modules Jul 8, 2022
@junaire
Copy link
Contributor Author

junaire commented Jul 8, 2022

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

@junaire
Copy link
Contributor Author

junaire commented Jul 8, 2022

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

@vgvassilev
Copy link
Member

@phsft-bot build!

@phsft-bot
Copy link
Collaborator

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

@vgvassilev
Copy link
Member

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

@vgvassilev
Copy link
Member

@phsft-bot build!

@phsft-bot
Copy link
Collaborator

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

@junaire
Copy link
Contributor Author

junaire commented Jul 10, 2022

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
Copy link
Contributor Author

junaire commented Jul 10, 2022

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

@davidlange6
Copy link
Contributor

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

@vgvassilev
Copy link
Member

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

Thanks!

@junaire
Copy link
Contributor Author

junaire commented Jul 12, 2022

@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?

@davidlange6
Copy link
Contributor

davidlange6 commented Jul 12, 2022 via email

@vgvassilev
Copy link
Member

@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.

Copy link
Member

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

DefinitionIDs[ND->getName()].push_back(OwningModule->getASTFile());
InterestingIDInfo &Info = DefinitionIDs[ND->getName()];

if (auto *NSD = dyn_cast_or_null<NamespaceDecl>(ND)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (auto *NSD = dyn_cast_or_null<NamespaceDecl>(ND)) {
if (auto *NSD = dyn_cast<NamespaceDecl>(ND)) {

I don't think ND can be nullptr.

@@ -316,10 +316,17 @@ bool TClingCallbacks::findInGlobalModuleIndex(DeclarationName Name, bool loadFir
// FIXME: We should load only the first available and rely on other callbacks
// such as RequireCompleteType and LookupUnqualified to load all.
GlobalModuleIndex::FileNameHitSet FoundModules;
bool K = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

if (Index->lookupIdentifier(Name.getAsString(), K, FoundModules)) {
if (K) {
if (gDebug > 2)
llvm::errs() << "\x1B[31m\"" << Name.getAsString() << "\" is a top level namespace,"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid adding console colors? Let's just use plain text which we can grep if the output is too much.

// when it's a NamespaceDecl.
unsigned Data = 0;

void setDeclKind(clang::Decl::Kind Kd) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void setDeclKind(clang::Decl::Kind Kd) {
void setDeclKind(clang::Decl::Kind K) {

@@ -340,6 +346,12 @@ bool GlobalModuleIndex::lookupIdentifier(StringRef Name, HitSet &Hits) {
}

bool GlobalModuleIndex::lookupIdentifier(StringRef Name, FileNameHitSet &Hits) {
bool K;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a better name here. Maybe IsThisANamespace?

@junaire
Copy link
Contributor Author

junaire commented Jul 16, 2022

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

@phsft-bot
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

Build failed on ROOT-debian10-i386/soversion.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

@phsft-bot
Copy link
Collaborator

@phsft-bot
Copy link
Collaborator

@vgvassilev
Copy link
Member

vgvassilev commented Oct 9, 2022

@junaire, the Missing transaction during deserialization means we needed to add PushTransactionRAII clingRAII(...) in the relevant interface, should be fairly straight-forward to fix assuming we have a debug build.

PS: It looks like we can add one of them in cling::execFindFunction cling::ParseProto::Parse.

@phsft-bot
Copy link
Collaborator

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
Copy link
Collaborator

Build failed on ROOT-debian10-i386/soversion.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

@phsft-bot
Copy link
Collaborator

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
Copy link
Collaborator

@davidlange6
Copy link
Contributor

davidlange6 commented Oct 11, 2022 via email

@Axel-Naumann
Copy link
Member

@davidlange6 is the RSS increase strictly due to this PR, or could it be due to some other change in master?

@davidlange6
Copy link
Contributor

davidlange6 commented Oct 11, 2022 via email

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 <jun@junz.org>
Signed-off-by: Jun Zhang <jun@junz.org>
@phsft-bot
Copy link
Collaborator

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
Copy link
Collaborator

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

Errors:

  • [2022-10-23T06:29:20.747Z] 54/2413 Test Disable unnecessary rebuilds on git changes #813: tutorial-multicore-mp101_fillNtuples ..............................................................***Failed Error regular expression found in output. Regex=[: error:] 0.40 sec
  • [2022-10-23T06:29:21.014Z] 56/2413 Test Refactored dict name checking in TCling [NFC] #820: tutorial-multicore-mt101_fillNtuples ..............................................................***Failed Error regular expression found in output. Regex=[: error:] 0.46 sec
  • [2022-10-23T06:30:27.271Z] 774/2413 Test [CLANG] Increase default value for -ftemplate-depth to 1024 #478: tutorial-cont-cnt001_basictseq ....................................................................***Failed Error regular expression found in output. Regex=[: error:] 0.43 sec
  • [2022-10-23T06:30:40.963Z] 849/2413 Test Unused make variable #554: tutorial-fitsio-FITS_tutorial3 ....................................................................***Failed Error regular expression found in output. Regex=[: error:] 0.51 sec
  • [2022-10-23T06:30:41.247Z] 851/2413 Test Run GL tests also in batch mode. #556: tutorial-fitsio-FITS_tutorial5 ....................................................................***Failed Error regular expression found in output. Regex=[: error:] 0.55 sec
  • [2022-10-23T06:30:41.247Z] 854/2413 Test [DOC] Update TDF release notes #557: tutorial-fitsio-FITS_tutorial6 ....................................................................***Failed Error regular expression found in output. Regex=[: error:] 0.54 sec
  • [2022-10-23T06:30:41.247Z] 857/2413 Test Fix Interpreter::getMacro returning 0 when using modules. #558: tutorial-fitsio-FITS_tutorial7 ....................................................................***Failed Error regular expression found in output. Regex=[: error:] 0.51 sec
  • [2022-10-23T06:30:51.199Z] 1112/2413 Test webgui: implement sync and async methods with optional callbacks #818: tutorial-multicore-mp201_parallelHistoFill ........................................................***Failed Error regular expression found in output. Regex=[: error:] 0.47 sec
  • [2022-10-23T06:30:51.199Z] 1113/2413 Test Fix missing SOURCES in treeplayer CMakeLists.txt #821: tutorial-multicore-mt102_readNtuplesFillHistosAndFit ..............................................***Failed Error regular expression found in output. Regex=[: error:] 0.48 sec
  • [2022-10-23T06:30:51.472Z] 1115/2413 Test Renamed RCASTOR back to RCastor #822: tutorial-multicore-mt103_fillNtupleFromMultipleThreads ............................................***Failed Error regular expression found in output. Regex=[: error:] 0.53 sec

And 3 more

Failing tests:

And 15 more

@phsft-bot
Copy link
Collaborator

Signed-off-by: Jun Zhang <jun@junz.org>
@phsft-bot
Copy link
Collaborator

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

@junaire junaire closed this by deleting the head repository Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants