holtwick / zeed-dom

🌱 Lightweight offline DOM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zeed dom is collecting all JSX elements it ever used in `USED_JSX`

floriankrueger opened this issue · comments

While digging into this issue with tiptap, my colleague @jcarvalho and I found the global variable USED_JSX to be the issue. Even serializing a simple document to HTML in a loop would quickly become slower and slower until it takes over a second to finish.

Memory was not an issue in our tests since the contents of USED_JSX where just the same elements over and over again so node itself could easily optimize that.

tiptap issue #2148 lists an example on how to make this happen. Would be great if you could give an estimate on how easily this might be fixable. I tried switching it from a global var to a parameter yesterday but there are so many points where I needed to pass the parameter to, and some of them were getters or setters, so that wasn't achievable.

Hi @floriankrueger I'll take a look. Thanks for investigating.

I made a quick change, to improve the speed of the USED_JSX part. I'll further investigate, if it is required in that form at all or if it can be replaced by something smarter and more consistent. I'll keep this bug open until the evaluation finished. Thanks.

Thank you for the intermediate fix! It'll improve the linear search a lot which should solve the reason for the performance issues that we were experiencing.

One concern remains even after the fix: Renders of previous documents are influencing upcoming documents. So the true returned by the check if (USED_JSX[c] … is incorrect at best and a minor security issue at worst (given that this is deciding on whether or now a certain string is escaped or rendered as html). Would you agree on that or am I misinterpreting something here?

I agree, this is bad design. I'll fix it but will need some time to do it well.

I removed the hack around USED_JSX altogether now. @floriankrueger , this should fix the concerns around global usage and also memory consumption. The code was old and made for a special purpose, now it should be up-to-date again. ;)

Change: b88ae22

This is amazing, thank you so much for the time!

No problem, thanks for pointing on the error and testing to make zeed-dom finally become a "Happy DOM" ;)