cybersemics / em

A beautiful, minimalistic note-taking app for personal sensemaking.
Other
280 stars 104 forks source link

strip slows down expandThoughts #2398

Open raineorshine opened 3 days ago

raineorshine commented 3 days ago

I found that a significant part of scripting and HTML parsing is done at the start of the interactions due to the expandThoughtsRecursive function using the strip function to perform sanitization on the values. In my tests, this accounts for at least 15-20% of the interaction time, with 1000 thoughts processed. This could be fixed by moving the sanitization to another stage that's not after every interaction. It is to be noted that if window-like virtualization is implemented, the impact of optimizing this would be reduced as the number of thoughts processed per interaction would be greatly reduced. WDYT?

Brave Browser 2024-09-15 19 23 20

It looks like strip was added to handle bold/italic/strikethrough. Thoughts that end in : should be pinned open, including <b>:</b>. See #1073. Solved in #1090 but note the unit tests appear to be false positives now.

We can remove strip and replace it with a much faster alternative that just strips closing tags.

raineorshine commented 2 days ago

Maybe this regex?

s.match(/:(<\/[^>]>)*$/g)

Matches a, <b>a:</b>, <i><b>a:</b></i>, etc.