-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Proposal: New CSS selector engine for jsdom #3644
Conversation
Hi! Thank you for all your work here. I think we should merge this, and I agree that querySelector and querySelectorAll are more important than matches and closest. Here are some things I'd appreciate from you before doing so, if you are able to make the time:
|
I'm planning to submit it as a separate PR.
With closest and matches, dom-selector is more than 4 times slower than happy-dom or linkeDom.
I will create change logs.
|
That sounds reasonable, although it'd be most helpful if we had some comparisons using the larger benchmark between nwsapi and dom-selector before merging. They don't need to be committed to the repository, but just something to check to make sure there's not a hidden significant performance issue with larger documents. I realize that, as you discussed in #3647, the comparison is difficult due to the number of failing selectors being different between the two implementations. Maybe you could just test the subset that pass in both, and report the results?
This is perfect. Thank you so much for doing this work. |
05ac445
to
6dc728f
Compare
Log of sizzle-speed with dom-selector:
Exception thrown by dom-selector:
So, nwsapi is about 3 times faster. |
3x slowdown is not great... I think we should probably still proceed, since jsdom in general favors correctness over speed and the selector engine problems have been significant recently. But, if there's anything we can do to improve performance before the next release, that would help a lot. I made a flamegraph using 0x and uploaded it here. I have to go out to dinner now but maybe it could be helpful for you... One thing I noticed is that sometimes you call expensive jsdom methods like the indexed or named getters on HTMLCollection. There might be faster ways to do that. (E.g. just using Like, I found this line |
Comparing v1.2.2...v1.2.6 · asamuzaK/domSelector Latest benchmark results:
The performance of See domSelector#performance for other comparisons with |
This update simplifies the integration with jsdom's exceptions, and fixes some of the WPTs introduced in this roll.
Thank you for all your work! Although the slowdown is unfortunate, I think it is great to have a maintained selector engine with modern features. I have tagged almost all open selectors issues as "maybe fixed (add tests to confirm)". It would be a nice bonus if you were willing to spend some time checking if there are existing WPTs covering the issue that are now passing, and leaving a comment on the issue so I can close them. Or, if there are no existing WPTs, we can work on adding them to the to-upstream WPTs. (Check out the existing files under This is not necessary, but it would be helpful to me and to all the people who have previously reported various issues! |
Although it does not follow the WPT format, issues reported on jsdom are tested on domSelector/test/jsdom-issues.test.js. |
Ah, thank you for pointing to that file! It's best to have them in WPT format so that the coverage can be applied to all browsers, and so that we have tests in the jsdom repo to more easily catch regressions. But if you'd rather not do the rewriting yourself, that's not a problem. I can work on it! |
In fact I think I can automate it :) https://chat.openai.com/share/3892a3b2-1c1c-4b9c-9a0f-fe3df1c317ae |
nwsapi
has been working great so far, and I appreciate the developer's hard work, butnwsapi
is unable to support Selectors Level 4 properly at the moment.You can find many selector-related bug reports in the
jsdom
issues.Therefore, I recommend changing to a different CSS selector engine dom-selector.
It supports many features of the Selectors Level 4 and also the Shadow Hosts.
Ref Supported CSS selectors
Benchmark results
For
closest()
andmatches()
,nwsapi
is about 15 times faster, but in reality,dom-selector
processed in 0.11 to 0.13 msec, so I don't think it's extremely slow.Rather, it is
querySelector()
andquerySelectorAll()
that often have speed performance issues, and in this benchmark,dom-selector
is about 4 times faster thannwsapi
.