Skip to content

Conversation

@bendikberg
Copy link
Contributor

Purpose

When a workspace is closed, a majority of the time is spent by nodes reacting to connector deletions. By unsubscribing from connector events before the a workspace closes, the time to get back to the main menu goes down substantially.

For the MaRS graph, this takes workspace close from about 8 to 4 seconds. For the Car_Configurator graph, this takes workspace close from about 2 minutes down to 40 seconds.

Performance

Old
closemodel

New
closemodel_improved_dispose

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

N/A

Reviewers

@mjkkirschner

FYIs

@dimven

@zeusongit zeusongit requested review from Copilot and removed request for Copilot May 22, 2025 15:31
Copy link
Contributor

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

Improves workspace close performance by disposing nodes and unsubscribing connector events before connectors are deleted.

  • Combines modification-event disabling and node disposal in WorkspaceModel.Clear()
  • Introduces ConnectorCollectionChanged event and disposal logic in PortModel and NodeModel
  • Adds Dispose overrides in ModelBase, NodeModel, and PortModel to clean up event subscriptions

Reviewed Changes

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

Show a summary per file
File Description
src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs Moved node disposal into initial loop in Clear
src/DynamoCore/Graph/Nodes/PortModel.cs Added connector‐collection event and Dispose
src/DynamoCore/Graph/Nodes/NodeModel.cs Centralized port cleanup in DisposePort and Dispose override
src/DynamoCore/Graph/ModelBase.cs Tracked disposal state with HasBeenDisposed
src/DynamoCore/Graph/Connectors/ConnectorModel.cs Simplified null‐safe connector removal
Files not reviewed (1)
  • src/DynamoCore/PublicAPI.Unshipped.txt: Language not supported
Comments suppressed due to low confidence (2)

src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs:1489

  • After disposing each node, consider clearing the Nodes collection (e.g., Nodes.Clear()) to release references and prevent potential memory leaks.
foreach (NodeModel node in Nodes)

src/DynamoCore/Graph/Nodes/NodeModel.cs:1340

  • [nitpick] The event name ConnectorCollectionChanged (singular) and handler ConnectorsCollectionChanged (plural) are inconsistent. Consider renaming to one form (e.g., ConnectorsCollectionChanged) for clarity.
p.ConnectorCollectionChanged += ConnectorsCollectionChanged;

MarginThickness = new Thickness(0);
Height = Math.Abs(Height) < 0.001 ? Configurations.PortHeightInPixels : Height;
}

Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

[nitpick] Add an XML doc comment for ConnectorCollectionChanged to explain when this event is raised and what subscribers should expect.

Suggested change
/// <summary>
/// Occurs when the collection of connectors associated with this port changes.
/// </summary>
/// <remarks>
/// This event is triggered whenever a connector is added to or removed from the port's connector collection.
/// Subscribers can use the event arguments to determine the nature of the change.
/// </remarks>

Copilot uses AI. Check for mistakes.
}


public override void Dispose()
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

In the Dispose override, invoke base.Dispose() after unsubscribing from InPorts/OutPorts and disposing ports to ensure cleanup completes before raising the Disposed event.

Copilot uses AI. Check for mistakes.
@reddyashish
Copy link
Contributor

Closing this as the changes are merged in a different PR.

@reddyashish reddyashish closed this Jun 5, 2025
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.

3 participants