Skip to content

perf(concerto-core): optimize DecoratorManager.decorateModels for targeted workloads - #1256

Closed
muhabdulkadir wants to merge 5 commits into
accordproject:mainfrom
muhabdulkadir:moh/perf-decorateModels
Closed

muhabdulkadir wants to merge 5 commits into
accordproject:mainfrom
muhabdulkadir:moh/perf-decorateModels

Conversation

@muhabdulkadir

@muhabdulkadir muhabdulkadir commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #

Rewrites decorateModels to resolve command targets upfront and only process models that commands actually touch, instead of cloning and traversing all models unconditionally.

  • Single pass over model files: targeted models are cloned and decorated, untouched models are re-parented directly into the new ModelManager (no rfdc, no ModelFile reconstruction)
  • Wildcard commands (no explicit namespace) are resolved against the model manager's existing Index to determine which specific namespaces they affect
  • If no wildcard commands exist, the resolution scan is skipped entirely
  • Zero-allocation falsyOrEqual replaces Set-based intersect
  • Namespace-level decorators applied once per model, not per-declaration
  • Dead code removed: pushMapValues, executeNamespaceCommand, isNamespaceTargetEnabled
  • remove rfdc clone and use a shallow clone to only copy what's mutated.

Performance

Benchmarked with skipValidationAndResolution: true (the hot path):

Scenario Before After Improvement
200 models, 4 commands → 4 models 4.49ms 0.92ms 4.9× faster
1 model, 3 commands 0.187ms 0.149ms 1.3x faster

The gains scale with the ratio of total models to targeted models. No regressions for single-model or all-models-targeted workloads.

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

…geted workloads

Signed-off-by: muhammed-abdulkadir <muhammed.abdulkadir@docusign.com>
@muhabdulkadir
muhabdulkadir force-pushed the moh/perf-decorateModels branch from e0ba7ff to c74bac2 Compare June 8, 2026 16:55
Signed-off-by: muhammed-abdulkadir <muhammed.abdulkadir@docusign.com>
Signed-off-by: muhammed-abdulkadir <muhammed.abdulkadir@docusign.com>
Signed-off-by: muhammed-abdulkadir <muhammed.abdulkadir@docusign.com>
…x wildcard check

Signed-off-by: muhammed-abdulkadir <muhammed.abdulkadir@docusign.com>
@muhabdulkadir
muhabdulkadir marked this pull request as draft June 9, 2026 00:44
@jamieshorten
jamieshorten requested a review from Copilot June 9, 2026 10:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Optimizes DecoratorManager.decorateModels in concerto-core to reduce work for targeted decorator command sets by resolving targets up front and only cloning/processing model files that commands actually affect.

Changes:

  • Reworked decorateModels to precompute command maps, determine targeted namespaces/models, and decorate only those models (with a shallow AST clone instead of deep cloning).
  • Added new helper utilities (shallowCloneModelAst, intersection/merge helpers, import pre-grouping) to reduce allocations and repeated work during decoration.
  • Expanded DecoratorManager unit tests to cover mixed explicit-namespace and wildcard command targeting scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/concerto-core/src/decoratormanager.ts Refactors decorateModels to apply decorators via targeted model processing, shallow AST cloning, and precomputed command/import maps.
packages/concerto-core/test/decoratormanager.js Adds tests for command target resolution behavior across explicit namespaces, wildcards, and overlapping target types.

Comment on lines +518 to +521
if (!isTargeted) {
mf.modelManager = newModelManager;
newModelManager.addModelFile(mf, null, null, true);
continue;
Comment on lines +373 to +378
const decl = decoratedModelManager.getType('test@1.0.0.Person');
decl.getDecorator('DeclTarget').should.not.be.null;
// SSN is also a ConceptDeclaration but 'DeclTarget' only targets declaration name 'Person'
const ssnDecl = decoratedModelManager.getType('test@1.0.0.SSN');
(ssnDecl.getDecorator('DeclTarget') === null).should.be.true;
});
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open with no activity. Remove the stale label or comment to keep it active. Only items with maintainer engagement are auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants