-
Notifications
You must be signed in to change notification settings - Fork 667
fix performance issue with error bars by suppressing property change notifications. #12553
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
Changes from all commits
e2f01e1
3ed1c2b
33fda0c
94326a0
2db52dc
1c5f118
695a882
e961b23
c118eb3
162ec76
f0a022f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace Dynamo.Core | ||
| { | ||
| /// <summary> | ||
| /// Class can be used to stop property change notifications from being raised if the client object | ||
| /// inherits from <see cref="NotificationObject"/> and uses RaisePropertyChanged to raise prop notifications. | ||
| /// Use like: | ||
| /// using (node.SetPropsToSupress("frozen")){ | ||
| /// node.frozen = true; | ||
| /// } | ||
| /// </summary> | ||
| internal class PropertyChangeManager : IDisposable | ||
| { | ||
| //TODO lock field during these accessors or use concurrent structure? | ||
| protected IEnumerable<string> PropertyNames { get; set; } | ||
| /// <summary> | ||
| /// Disable property change notifications for a list of a props. | ||
| /// The previous set of suppressed notifications will be cleared. | ||
| /// This API is meant to be used only for a short time and Dispose should be | ||
| /// called on the object this call returns. | ||
| /// </summary> | ||
| /// <param name="props"></param> | ||
| /// <returns></returns> | ||
| public PropertyChangeManager SetPropsToSuppress(params string[] props) | ||
| { | ||
| PropertyNames = props; | ||
| return this; | ||
| } | ||
| /// <summary> | ||
| /// Disposing this class will allow prop notifications to be raised. | ||
| /// </summary> | ||
| public void Dispose() | ||
| { | ||
| PropertyNames = null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to trigger the property change notification on dispose?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we do not want to trigger the updates on dispose - or at least that will not make this class useful for the problem I am trying to solve with how I am currently using it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like we could improve this class in the future to also have a method called |
||
| } | ||
| /// <summary> | ||
| /// Checks if notifications are suppressed for a specific property. | ||
| /// </summary> | ||
| /// <param name="prop"></param> | ||
| /// <returns></returns> | ||
| public bool ShouldRaiseNotification(string prop) | ||
| { | ||
| if(PropertyNames is null) | ||
| { | ||
| return true; | ||
| } | ||
| return !PropertyNames.Contains(prop); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -750,8 +750,10 @@ private void OnUpdateGraphCompleted(AsyncTask task) | |
| var node = workspace.Nodes.FirstOrDefault(n => n.GUID == guid); | ||
| if (node == null) | ||
| continue; | ||
|
|
||
| node.Warning(message.Value); // Update node warning message. | ||
| using (node.PropertyChangeManager.SetPropsToSuppress(nameof(NodeModel.ToolTipText), nameof(NodeModel.State))) | ||
aparajit-pratap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| node.Warning(message.Value); // Update node warning message. | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we do not need the property change notification at all here? We are changing model data without notifying the ui ...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that is exactly the point, we need to completely avoid triggering the prop notifications for these changes and trigger the ui update ourselves at the correct time.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see changes to |
||
| } | ||
|
|
||
| // Notify listeners (optional) of completion. | ||
|
|
@@ -767,8 +769,8 @@ private void OnUpdateGraphCompleted(AsyncTask task) | |
| // Dispatch the failure message display for execution on UI thread. | ||
| // | ||
| EvaluationCompletedEventArgs e = task.Exception == null || IsTestMode | ||
| ? new EvaluationCompletedEventArgs(true) | ||
| : new EvaluationCompletedEventArgs(true, task.Exception); | ||
| ? new EvaluationCompletedEventArgs(true,messages.Keys,null) | ||
| : new EvaluationCompletedEventArgs(true, messages.Keys, task.Exception); | ||
|
|
||
| EvaluationCount ++; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see O(n) worst-case complexity as it would need to search for the property in
PropertyNamesif it isn'tnull.