Skip to content

DynamoModel startup time improvements #16236

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dimven-adsk
Copy link
Contributor

Purpose

This PR focuses on the DynamoModel startup performance, specifically when running under Revit and with the 10 most popular packages installed. These modified code paths are not as critical under Dynamo core because they are not visited as often.

Snapshot of the current performance:

devenv_AO7R6bTqDR

Proposed changes:

devenv_rCDMplDzBr

  • we can cache the assembly reflection calls instead of calling them for every single node definition documentation
  • we can remove or reduce the linq calls because they exacerbate hot paths
  • we can avoid concatenating three or more strings with the + operator, because that creates unnecessary calls

These changes do not change the underlying logic but can improve the model startup performance by 4~5%.

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB

Release Notes

(FILL ME IN) Brief description of the fix / enhancement. Use N/A to indicate that the changes in this pull request do not apply to Release Notes. Mandatory section

Reviewers

(FILL ME IN) Reviewer 1 (If possible, assign the Reviewer for the PR)

(FILL ME IN, optional) Any additional notes to reviewers or testers.

FYIs

(FILL ME IN, Optional) Names of anyone else you wish to be notified of

Sorry, something went wrong.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves DynamoModel startup performance by replacing expensive LINQ and string concatenations with cached loops and interpolations, and introduces caching for assembly reflection calls.

  • Add a null guard on SearchModel and replace LINQ with a manual loop in the custom node manager hot path
  • Simplify XML documentation lookup with early returns and string interpolation
  • Introduce an assembly load context cache in StartupUtils and update ignore list entries

Reviewed Changes

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

Show a summary per file
File Description
src/DynamoCore/Models/DynamoModel.cs Guard against null SearchModel and avoid LINQ in hot path for custom node lookups
src/DynamoCore/Library/XmlDocumentationExtensions.cs Consolidate null/empty checks and use string interpolation for fully qualified member names
src/DynamoCore/Library/LibraryCustomization.cs Swap ContainsKey + indexer for TryGetValue
src/DynamoCore/Library/FunctionDescriptor.cs Replace multi-step filtering and concatenations with OfType and interpolated strings
src/DynamoApplications/StartupUtils.cs Add LoadedAssembliesCache, update ignore list entries, and refactor assembly mismatch logic
Comments suppressed due to low confidence (4)

src/DynamoCore/Models/DynamoModel.cs:1523

  • [nitpick] The null-conditional operator on cnSearch?.Path is redundant since entry is not CustomNodeSearchElement cnSearch already ensures cnSearch is non-null. You can simplify to cnSearch.Path.
if (entry is not CustomNodeSearchElement cnSearch || string.IsNullOrWhiteSpace(cnSearch?.Path) || ...)

src/DynamoApplications/StartupUtils.cs:442

  • [nitpick] Private static field names should follow camelCase naming conventions (e.g., loadedAssembliesCache) to match the project's style.
private static Dictionary<string, Dictionary<string, (Assembly, AssemblyName)>> LoadedAssembliesCache = new Dictionary<string, Dictionary<string, (Assembly, AssemblyName)>>();

src/DynamoApplications/StartupUtils.cs:463

  • The new caching logic for LoadedAssembliesCache should be covered by unit tests to verify cache population, retrieval, and update behavior under different AssemblyLoadContext scenarios.
if (!LoadedAssembliesCache.TryGetValue(loadContext.Name, out var loadedAssemblies))

src/DynamoApplications/StartupUtils.cs:429

  • [nitpick] Consider using the C# alias string[] instead of String[] for built-in types to align with common style guidelines.
private static readonly String[] assemblyNamesToIgnore = { "Newtonsoft.Json", "RevitAPI", "RevitAPIUI" };

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

Successfully merging this pull request may close these issues.

None yet

2 participants