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.
List of Affected Nodes/Modules
Element.GetParameterByName
Element.SetParameterByName
Current Performance
This PR is related to #1, as it affects a similar scenario - finding parameters by their name is expensive. In the previous PR we skip the step getting the parameter definitions but we were still paying the cost of querying an element's parameters by name. In this PR we explore the option of instead caching the results of that query and fetching the element's parameters by the definition. As discussed previously, the current performance is less than ideal:
Proposed Performance
If we have a simple lookup dictionary that stores a list of all found definitions that match that name, it is likely that we can reuse the expected definition. The cache will be used only for the duration of the execution and cleared in case the user modifies the project parameters. By keeping the same parameter priority logic (parameter with latest id is chosen first), we should ensure the original intent is preserved.
Dynamo Tuneup Comparison
Collecting ~55k elements and fetching a single parameter value we drop form around 9 seconds[1] on average down to about 1.5 seconds. Keep in mind that this is an ideal scenario, because all of the elements we collected are from a single category and share the same definition. A mixed collection of parameter names and elements that don't necessarily share the same definition will perform worse.
Checklist
[1] The graph was simplified compared to the version in #1