Repository navigation
Conversation
Contributor
Author
|
Wrong repo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull request:
Binding an object to a templated class by name, for example
cppjit.bind_object(addr, "std::vector<double>"), whichTDirectoryFile.Getdoes for every object it returns, grows the memory by about 11 kB on every call. This doesn't happen with ROOT 6.40:Changes or fixes:
interop::GetScopedoesn't remember what a templated name resolved to, so every lookup of the same name repeats this:AppendTypesSlowdeclares a new__cppjit_interop_sNvariable in the interpreter to resolve the name. This is most of the growth.Cpp::GetScopefails on the name. The failed lookup makesTClingCallbacks::LookupObjecttry to autoload it, andTCling::GetClassSharedLibsparses the name again withcling::LookupHelper::findScope. Forstd::vector<double>this adds new AST nodes, about 350 B per call (found with heaptrack).This PR caches successful lookups of templated names at the start of
interop::GetScope, so both are skipped. Failed lookups aren't cached because they may succeed once more declarations are available. With the change, the growth after 20000 calls is 0 kB for bothvector<double>andstd::vector<double>.compiler-research/cppjit#155 is related, but it doesn't fully fix this issue. It memoizes the result inside
AppendTypesSlow, which removes the new variable on every call, including for the other callers ofAppendTypesSlowsuch as overload ranking. However, the failingCpp::GetScopeand the autoload happen beforeAppendTypesSlowis called. Caching at that later point, which I tried first, still leavesstd::vector<double>growing by a few hundred bytes per call. The two changes are complementary. The sameinterop::GetScopecode is also in cppjit'smainbranch, without the ROOT-specific autoload part.The new test
test57_repeated_template_scope_lookupfails without the change (the memory grows by 25 MB with a threshold of 8 MB) and passes with it.Checklist:
Tested on AlmaLinux 9 with the dev3 view (gcc 16): all 26 cppjit test files pass through ctest.