-
Notifications
You must be signed in to change notification settings - Fork 42
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
Greedy script? #17
Comments
Hi @ZzZombo. Your performance issue sounds plausible. I'll be looking into it soon. |
There are a few issues here (without delving into the code):
|
This shouldn't break anything. Nodes are already inserted/removed by the time an observer handles such actions. Same goes for all the other event types. |
@ZzZombo I have 50+ selectors registered, and have no impacts on performance whatsoever. Are you sure that you're only initializing your selectors once? Because if they get reinitialized, let's say at partial loads on a dynamic page, that will choke the page in no time. I know this from my own experience, because I have to do just that - detect newly inserted DOM elements at every partial ajax page load. The site went crazy when selectors were registered. I wrote a deInitialize func, removing either all or defined selectors, that I attached to a jQuery on hashchange callback. Works great! @pie6k I'll fork your script and then I'll make a pull request, you are free to incorporate my added func as you see fit (if at all.) |
The amount of selectors has no impact on performance whatsoever. It's the actual DOM that matters, whether it's a single element "Hello, world" page or both element heavy and dynamically changing one makes huge difference. Using this library in my userscript had actually made my browser ask me if I want to kill unresponsive page or not several times. I no longer use it, having learnt to use the MutationObserver API directly, and while the browser may choke sometimes on complex pages, it still yields better response times overall over the previous version of my script. |
Edit: Deleted to avoid confusion. The content of this post is out-of-date. |
The third feature has also now been implemented in #19. |
You made the wrong call. Please read the API specs, or just do a simple test with debug output to browser console. When MutationObserver fires a callback, all changes in the batch it provides have ALREADY executed, as I have said it so in my first response 😩. That's why you are provided with the changed element and optionally |
Have you seen and tested the changes? I'm not sure I follow your reasoning. I know that the element has already been mutated before the observer sees it. That's not a problem. If fact, if the change were not visible, then it would be impossible to query the mutated nodes for matches. So, this seems completely irrelevant to me. I may have not explained my changes correctly. Disregard the above. I will explain it afresh. What I have done in #19 and #21 is to address the following concerns:
The plugin now ignores mutation types that are not
By default, the plugin will observe all elements (that is,
Or:
Furthermore, the plugin will not query the entire document for nodes matching the selector. It will only check the mutated node for a match (or its descendants or parents depending upon the complexity of the selector.) |
Did you want to be able to set |
|
I agree. I removed that in #21. |
Then great. Hope to use the updated version in a project soon. |
Very good. The performance improvements haven't been released yet. If you want to test with your application, please do so by installing the test branch:
I also exposed observer options in 573fb61 |
These performance changes have been released under 1.2.0. |
If I read the code right, nowhere there the
mutations
variable is ever referenced. How does the script work then? Does it mean that for all mutations it subscribed to to all elements in the document, it will run callbacks? Huh? That explains the huge performance hit I witness ever since I added the script to my userscript.The text was updated successfully, but these errors were encountered: