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

Simplify dom text scanner #453

Merged

Conversation

toasted-nutbread
Copy link

@toasted-nutbread toasted-nutbread commented Dec 26, 2023

See #431 (comment):

My comment is a bit late on this, but these sub-functions should probably just be modifying the seekTextNoteDetails value that is passed into it. As it stands right now, it's repeatedly constructing and destructuring a large structure in a high-bandwidth code-path, which is probably not great. Obviously this project doesn't have performance tests currently, so I don't have hard data to back this up, but I'd imagine that this is likely less efficient.

One of the reasons why this code path was originally somewhat messy was because it was a highly-used function. That's why it was doing the weird thing where it would assign all of the member fields to local variables first, and then restore them after: for (presumably) faster access in a loop. However, now that that effect is no longer being used, there is really no reason to do that, and instead the member fields should be used directly.

This is what it would look like:
https://github.com/toasted-nutbread/yomichan/commits/simplify-dom-text-scanner/

But I'm also not sure if there's a strong benefit of making that change vs just leaving the loop in the function. There's probably a lot of code locality and caching stuff that goes on in JS there, so it's hard to say what is the best way to do this in the long run without performance benchmarks.

@toasted-nutbread toasted-nutbread requested a review from a team as a code owner December 26, 2023 14:13
Copy link

✔️ No visual differences introduced by this PR.

View Playwright Report (note: open the "playwright-report" artifact)

@toasted-nutbread toasted-nutbread marked this pull request as draft December 26, 2023 14:36
@Casheeew
Copy link
Member

Casheeew commented Dec 27, 2023

If there are changes in performance characteristics, is it too bad to leave in a couple labels for the time being? Also prevents hacky ways such as https://github.com/themoeway/yomitan/blob/8e95d99e6a1891eaf9331f6384fa3b1a1065b871/ext/js/display/display.js#L1488

@toasted-nutbread
Copy link
Author

If there are changes in performance characteristics, is it too bad to leave in a couple labels for the time being? Also prevents hacky ways such as

https://github.com/themoeway/yomitan/blob/8e95d99e6a1891eaf9331f6384fa3b1a1065b871/ext/js/display/display.js#L1488

That's another situation where the inner loop should be a function. It's also not a highly traversed code path.

The code that was changed in this and previous PRs was already just a single loop, albeit with an ugly body.

@toasted-nutbread toasted-nutbread marked this pull request as ready for review December 28, 2023 14:27
@djahandarie djahandarie added this pull request to the merge queue Dec 29, 2023
Merged via the queue into yomidevs:master with commit 476d754 Dec 29, 2023
5 checks passed
@djahandarie djahandarie added the kind/meta The issue or PR is meta label Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/meta The issue or PR is meta
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants