Skip to content

perf(xtext): compute the resource of the scope context once per lookup - #1716

Merged
rubenporras merged 1 commit into
dsldevkit:masterfrom
rubenporras:perf/scope-provider-context-resource
Dec 4, 2026
Merged

rubenporras merged 1 commit into
dsldevkit:masterfrom
rubenporras:perf/scope-provider-context-resource

Conversation

@rubenporras

Copy link
Copy Markdown
Member

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

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 joaodinissf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

  1. com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/scoping/AbstractPolymorphicScopeProvider.java:413 (P3, no change requested): contained is now read before originalResource.getResourceSet(), doGlobalCache(...), getGlobalCacheKey(...) and resourceSetScopeCache.get(...), where the old code read eResource() again inside doCache after them. The result differs only if a subclass override of doGlobalCache, the cache key computer or the cache get attaches or detaches the context in between. No override of doCache/doGlobalCache exists in this repository; downstream overrides were not checked.
  2. 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, in registerIfForeignObject (:130) and in internalGetScope (:413, a second time for the EClass fallback at :167). Removing these needs a new overload, so it is out of scope for "signatures unchanged".
  3. Tests (P3, doubt): I found no test that targets the cache checks of internalGetScope directly, 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 to registerForeignObject, nothing runs between the former three eResource() calls; a null context fails with an NPE at the same point.
  • internalGetScope (:411-431): original resource null (no eResource() call, as before); resource set null or no IResourceSetScopeCache adapter (old code reached doCache, which computed the resource); adapter present (old doGlobalCache computed it). So the new code never computes the resource where the old one did not. Uncontained context: neither protected doGlobalCache nor doCache is called, as before. Hit and miss in both caches, the NO_SCOPE handling and the IllegalArgumentException for a named element of another type behave as before.
  • API: no public or protected member added, removed or changed; the protected doGlobalCache/doCache/registerForeignObject/doGetScope get the same calls in the same order with the same arguments.
  • Version: com.avaloq.tools.ddk.xtext is 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

@joaodinissf joaodinissf added the review:approved Current head approved by review; CI and human merge gates still apply. label Dec 4, 2026
@rubenporras
rubenporras added this pull request to the merge queue Dec 4, 2026
Merged via the queue into dsldevkit:master with commit 9482930 Dec 4, 2026
4 checks passed
@rubenporras
rubenporras deleted the perf/scope-provider-context-resource branch December 4, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved Current head approved by review; CI and human merge gates still apply.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants