heyman / heynote

A dedicated scratchpad for developers
https://heynote.com
Other
3.76k stars 183 forks source link

Bug: improve speed of getBlocks() #239

Closed kjk closed 1 month ago

kjk commented 1 month ago

On large documents (say 300 kB with multiple blocks) getBlocks() is called every time delete happens.

It forces syntax parsing of the whole document which can be slow. In my test document it would take > 300 ms. During that time the document is shown un-styled, meaning heynote markings would show for a while.

This was reported on my fork https://github.com/kjk/edna/issues/22 and I fixed it by rewriting getBlocks() to use string.indexOf(), which made it run under 2 ms.

The commit is https://github.com/kjk/edna/commit/701dda8e09a083b1df8b8a2d343b511101f9d19a, feel free to take this code or disregard.

heyman commented 1 month ago

Nice! This has now been fixed in #241. I ended up with a solution that uses the syntax tree if it's available, and otherwise use String.indexOf().