Skip to content

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

Closed
ryuapp wants to merge 1 commit intohonojs:mainfrom
ryuapp:improve-performance-find-insert-before
Closed

feat(jsx/dom): improve performance of findInsertBefore#3203
ryuapp wants to merge 1 commit intohonojs:mainfrom
ryuapp:improve-performance-find-insert-before

Conversation

@ryuapp
Copy link
Copy Markdown
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

@codecov
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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