code-input icon indicating copy to clipboard operation
code-input copied to clipboard

Prevent UI hangs in find and replace / go to line processing

Open WebCoder49 opened this issue 1 month ago • 1 comments

Typing some text to find and replace or a line number to go to can cause slowness now and make the next keystroke not be displayed for a while, so the processing to find and highlight text or find line length should not be carried out for every fast keystroke. Debounce it like this or with the requestAnimationFrame method used in code-input.js core.

This will probably require added timeouts for the findandreplace/gotoline tests.

WebCoder49 avatar Nov 06 '25 22:11 WebCoder49

In the find and replace plugin, debouncing is already implemented, as is limiting of the number of displayed matches (const CODE_INPUT_FIND_AND_REPLACE_MATCH_BLOCK_SIZE). There are two further actions that can be taken:

  • (Good option, potentially together with the bad option for a better option) Change the match-displaying algorithm so it does not highlight each match separately but rather sweeps through all at once (changes time complexity from O(nm) to O(n), where n is the length of the code and m is the number of matches).
  • (Bad option; use only if necessary) Increase the debouncing interval, and decrease the number of displayed matches. Leads to slightly worse user experience.

WebCoder49 avatar Nov 15 '25 17:11 WebCoder49

The match-displaying algorithm will also be a good foundation for the selective-highlighting performance improvements.

WebCoder49 avatar Dec 07 '25 17:12 WebCoder49