We use decorations to highlight words and basically add “real-time” links to text (e.g. annotations, spellcheck markers, etc.). This means that the plugin runs over the full text on all transactions that change the content in some way.
I came across Decorations performance - #5 by marijn which says to store the decorations in a plugin state, but even then: how do we handle cases where a user is just typing at the end of the text (or within a single paragraph) while the rest of the document isn’t any different?
Are there ways to basically say “from 0 - 1000 we can reuse, then update just the rest”? We already have a fast lookup of things, but some users still report performance issues in edge cases (or when there’s too much to go over, like 50k word documents).
Yes, you can do this with RangeSet.update. Determine which area you want to redraw, pass that range as filterFrom/filterTo with a filter that always returns false, and pass the newly drawn decorations in add. (You’ll want to make sure you map the set before updating, so that its positions actually correspond to the post-change document.)
Okay, cool! I am guessing that I can get the “affected range” from the transaction steps? Because I technically don’t know what the user was doing, so having a way to know which parts to focus on would be good.