How to implement caching for incremental re-highlighting
masterFor text editors requiring high performance, syntect's API allows for a caching strategy to achieve near-instantaneous re-renders during edits.
Recommended Strategy:
- Initial Parse: Every ~1000 lines, copy the current parse state into a side-buffer.
- On Edit:
- Search backwards in the parse state cache for the last state recorded before the edit location.
- Start a background task to re-highlight from that cached state forward.
- Render the new changes once the background task reaches the current editor viewport.
- Concurrency: When a new edit occurs, stop any existing background highlighting jobs to ensure the thread is always working on the most up-to-date text state.