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

feat(jsx/dom): improve performance of findInsertBefore #3203

Closed

Conversation

ryuapp
Copy link
Contributor

@ryuapp ryuapp commented Jul 28, 2024

Fix #3201

I honestly don't know much about it, but eliminating recursive calls improves performance.
We may need accurate benchmarks or tests.

I tried with the following example:
https://github.com/ryuapp/hono-vite-template
At least increasing the issue example didn't slow it down.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

Copy link

codecov bot commented Jul 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.20%. Comparing base (cdd48f4) to head (3078b54).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3203   +/-   ##
=======================================
  Coverage   96.20%   96.20%           
=======================================
  Files         151      151           
  Lines       15074    15081    +7     
  Branches     2718     2647   -71     
=======================================
+ Hits        14502    14509    +7     
  Misses        572      572           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@usualoma
Copy link
Member

Hi @ryuapp, Thank you for doing the research. I appreciate your work.

There is potential for performance improvement by stopping recursive calls.

However, the essential cause of #3201 seems to be elsewhere. I will create a PR after this, but it will likely be a fix.

diff --git a/src/jsx/dom/render.ts b/src/jsx/dom/render.ts
index dbb8478b..6b18f2ae 100644
--- a/src/jsx/dom/render.ts
+++ b/src/jsx/dom/render.ts
@@ -279,7 +279,7 @@ const findInsertBefore = (node: Node | undefined): SupportedElement | Text | nul
     return node.e
   }
 
-  if (node.vC) {
+  if (node.vC && node.pP) {
     for (let i = 0, len = node.vC.length; i < len; i++) {
       const e = findInsertBefore(node.vC[i])
       if (e) {

@ryuapp
Copy link
Contributor Author

ryuapp commented Jul 29, 2024

Great work, @usualoma.
The issue has been fixed in #3205, so I close this PR.

@ryuapp ryuapp closed this Jul 29, 2024
@yusukebe
Copy link
Member

@ryuapp Thanks!

@ryuapp ryuapp deleted the improve-performance-find-insert-before branch July 30, 2024 05:59
@usualoma usualoma mentioned this pull request Aug 18, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSX DOM render extremely slow
3 participants