WorkspaceViewModel fast node and connector lookup #15857
+51
−37
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.
Purpose
When changing many nodes and connectors at the same time during deletion, undo and redo, a lot of time is spent looking for the end nodes of connectors. The current implementation of the WorkspaceViewModel uses an ObservableCollection to hold the nodes, which essentially is the same as a list. Since the connector ends are being looked up using linq, this has much worse performance than looking up nodes in a dictionary.
This PR adds a dictionary that lives alongside the ObservableCollection. This increases memory usage somewhat, but means lookups can be much faster.
Deleting and undoing a large amount of nodes on the MaRS model takes delete from about 10 to 5 seconds, and undo from about 40 to aobut 5 seconds.
Doing the same on the Car_Configurator takes the delete time from about 2m20s to about 12 seconds, and undo from about 2m35s to 30s.
It also shaves off a little bit of time when opening a workspace from json.
Performance
Deletion (old)


Deletion (new)
Undo deletion (old)


Undo deletion (new)
Open json from path (old)


Open json from path (new)
Declarations
Check these if you believe they are true
*.resx
filesRelease Notes
N/A
Reviewers
@mjkkirschner
FYIs
@dimven