Skip to content
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

Fix Shadow DOM performance issue and restore its support #3365

Merged
merged 4 commits into from
Apr 8, 2024

Conversation

heiwiper
Copy link
Contributor

@heiwiper heiwiper commented Mar 23, 2024

Description

The algorithm for the macro rqsa has been improved by using Tree Walker instead of Node Iterator and the matching elements are now sorted in depth first order. The sorting order was necessary to fix the performance issue, You can read more about the details of that issue in the references issues below.

The algorithm for the macro rqs-nyxt-id has been improved by directly retrieving Shadow root elements if the matching element cannot be found by executing querySelect function. Previously, we would walk through all elements to check whether each element is a Shadow root. Please note that we can't use this same method in the rqsa macro because the that macro might be executed on elements that do not yet have nyxt attributes assigned which isn't the case for rqs-nyxt-id.

Fixes #3295

Checklist:

  • Git branch state is mergable.
  • Changelog is up to date (via a separate commit).
  • New dependencies are accounted for.
  • Documentation is up to date.
  • Compilation and tests ((asdf:test-system :nyxt/<renderer>))
    • No new compilation warnings.
    • Tests are sufficient.

@heiwiper heiwiper marked this pull request as draft March 23, 2024 19:56
@jmercouris
Copy link
Member

Thank you @heiwiper! I want you to know that this PR is not unnoticed!

@heiwiper
Copy link
Contributor Author

heiwiper commented Apr 2, 2024

Thanks for the followup! I totally understand, especially considering that the related issue is marked as low priority.

@aadcg
Copy link
Member

aadcg commented Apr 4, 2024

@heiwiper I've tested this branch and I think the results are amazing!

I took the richest URL in terms of hints (~8k) and I can't notice any difference between this branch and master. That means that shadow DOM support adds no overhead, as intended.

And the feature is working too. I've tested it with https://developer.servicenow.com/dev.do.

In short, I think it's mostly done. Please mark it as ready and add a changelog entry. We'll integrate these changes in the next release in the 3 series.

Thanks!

heiwiper added 3 commits April 8, 2024 05:54
Avoids iterating through all DOM nodes to walk through shadow DOM
elements. Instead, we make use of the nyxt class 'nyxt-shadow-dom'.

Note that the use of 'do' loop macro makes sure we get that parenscript
generates the desired code in javascript.
Unlike the macro 'rqs-nyxt-id', we don't make use of 'nyxt-shadow-root'
attribute because the macro 'rqsa' might get called befoore the DOM is update
through the function 'update-document-model'.
We use the TreeWalker for this algorithm based on the benchmarks of the
following StackOverflow response https://stackoverflow.com/a/64551276

Ensure that the results produced by rqsa are sorted in depth first algorithm so
that it matches the generated hints order which is produced in the same order
according to the doocumentation of the function 'clss:select'.

Note that sorting the output array based on 'nyxt-identifier' is not possible
because elements that are dynamically added to the DOM are assigned a
'nyxt-identifier' that is greater than the last generated identifier, so it
would break the depth-first order. Add to that the fact that 'rqsa' macro might
be called on elements that do not have nyxt-attributes as mentioned previously.
@heiwiper heiwiper force-pushed the shadow-hinting-performance branch from 4556216 to 94459c0 Compare April 8, 2024 05:03
@heiwiper
Copy link
Contributor Author

heiwiper commented Apr 8, 2024

I have just added the changelog entry and rebased into master.

Thanks for taking the time to test these changes!

@heiwiper heiwiper marked this pull request as ready for review April 8, 2024 05:15
@aadcg aadcg merged commit bb3aaca into atlas-engineer:master Apr 8, 2024
3 checks passed
@aadcg
Copy link
Member

aadcg commented Apr 8, 2024

Thanks again @heiwiper.

@heiwiper
Copy link
Contributor Author

heiwiper commented Apr 8, 2024

My pleasure!

Feel free to tag me in related issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

hint-mode Shadow DOM elements support
3 participants