Repository navigation
perf(xtext): compute the resource of the scope context once per lookup - #1716
Merged
rubenporras merged 1 commit intoDec 4, 2026
Merged
rubenporras merged 1 commit into
rubenporras merged 1 commit into
Conversation
EObject.eResource() walks up the containers of an object to its root. The scope provider called it repeatedly for the same context: getScope with a scope name and original resource up to three times to detect a foreign context object, and internalGetScope once in doGlobalCache and once more in doCache to check that the context is contained in a resource. As generated scope providers call internalGetScope for every container of a context, this added up to about 2,800 samples (~28 s) on the build thread in the second phase of a full ASMD build. getScope now computes the resource once to check for a foreign object, and internalGetScope checks the containment once for both cache checks. One of them is always made when there is an original resource, so this never computes the resource where it did not before. The protected methods and their signatures are unchanged. Assisted-by: Claude:claude-opus-5-5
joaodinissf
approved these changes
Dec 4, 2026
joaodinissf
left a comment
Collaborator
There was a problem hiding this comment.
Approve: no P1/P2 findings; the change is behaviourally equivalent to the base on every branch I traced, and the claims in the description hold.
com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/scoping/AbstractPolymorphicScopeProvider.java:413(P3, no change requested):containedis now read beforeoriginalResource.getResourceSet(),doGlobalCache(...),getGlobalCacheKey(...)andresourceSetScopeCache.get(...), where the old code readeResource()again insidedoCacheafter them. The result differs only if a subclass override ofdoGlobalCache, the cache key computer or the cachegetattaches or detaches the context in between. No override ofdoCache/doGlobalCacheexists in this repository; downstream overrides were not checked.AbstractPolymorphicScopeProvider.java:145,:267(P3, optional follow-up): the entry points without an original resource still compute the resource twice or more per lookup:getScope(context, reference)at the call site, inregisterIfForeignObject(:130) and ininternalGetScope(:413, a second time for theEClassfallback at :167). Removing these needs a new overload, so it is out of scope for "signatures unchanged".- Tests (P3, doubt): I found no test that targets the cache checks of
internalGetScopedirectly, in particular the branch with a context not contained in a resource; coverage is indirect through the generated scope providers. The gap exists on the base as well, so I do not ask for a test here.
Checked and found unchanged:
getScope(..., scopeName, originalResource)(:162, :249): same condition, same arguments toregisterForeignObject, nothing runs between the former threeeResource()calls; anullcontext fails with an NPE at the same point.internalGetScope(:411-431): original resourcenull(noeResource()call, as before); resource setnullor noIResourceSetScopeCacheadapter (old code reacheddoCache, which computed the resource); adapter present (olddoGlobalCachecomputed it). So the new code never computes the resource where the old one did not. Uncontained context: neither protecteddoGlobalCachenordoCacheis called, as before. Hit and miss in both caches, theNO_SCOPEhandling and theIllegalArgumentExceptionfor a named element of another type behave as before.- API: no public or protected member added, removed or changed; the protected
doGlobalCache/doCache/registerForeignObject/doGetScopeget the same calls in the same order with the same arguments. - Version:
com.avaloq.tools.ddk.xtextis at 17.5.1 against 17.5.0 in v19.4.0, so no bump is needed for this micro change. - CI on the head is green (checkstyle, line-endings, maven-verify, pmd).
Assisted-by: Claude:claude-fable-5-2
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.
EObject.eResource() walks up the containers of an object to its root. The scope provider called it repeatedly for the same context: getScope with a scope name and original resource up to three times to detect a foreign context object, and internalGetScope once in doGlobalCache and once more in doCache to check that the context is contained in a resource. As generated scope providers call internalGetScope for every container of a context, this added up to about 2,800 samples (~28 s) on the build thread in the second phase of a full ASMD build.
getScope now computes the resource once to check for a foreign object, and internalGetScope checks the containment once for both cache checks. One of them is always made when there is an original resource, so this never computes the resource where it did not before. The protected methods and their signatures are unchanged.
Assisted-by: Claude:claude-opus-5-5