-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Optimized work with Listener list #308
Optimized work with Listener list #308
Conversation
I found an interesting problem. |
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.
@Karnah please see comment
Can we introduce some kind of a global static list there References with these Exceptions are added and then in later runs can be just deleted. This is not perfect but a little bit like the .net garbage collection.
I think an AggregatedException makes sense. @Karnah TIP for you. Install Grammarly to help you fix most of the English errors in these comments even with the unpaid version. |
I have an idea to make |
* ClearDeadReferences is called only inside ListenersList
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.
@Karnah please check the comments
src/Engine/ListenerList.cs
Outdated
/// </summary> | ||
public void AddListener(IDictionaryEventListener listener) | ||
{ | ||
ClearDeadReferences(); |
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.
does it make sense to call it here? because it does not search for new dead references like in GetListeners?
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 did it, because of a subsequence of operations.
- Call
GetListeners
-> it creates list of dead references - Call any other method -> references are removed before main operation
But I found a better solution which is not obvious. If wrap foreach (var listener in listeners)
with try/finally and call ClearDeadReferences
in finally
block -> reference will be always deleted after this method call, even if calling code use break
;
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.
can you push this change, with the "finally". That sounds great to me.
Listeners list has the same problems which had
NestedMarkupExtension
:AddListener
was O(N) + constant for deleting weak refernces + memory using for 'ToList()' call. Now - O(lgN).RemoveListener
was O(N) + constant for deleting dead weak refernces + memory using for 'ToList()' call. Now - O(lgN).Invoke
andEnumerateListeners
has problem with memory ('ToList()' call) + deleting dead weak refernces.So, I hope this changing will increase perfomence on all operations with listener list.
p.s. Now
Invoke
method all executing under lock. It seems to me and I hope this won't have some bad effects