david
(David Taylor)
September 12, 2024, 2:01pm
8
The performance regression was introduced by this commit: FIX: when replacing text in composer maintain history (#28537) · discourse/discourse@e25578d · GitHub , so it lines up with the ‘about 2 weeks’ you mentioned in the OP @piffy .
The problem is that execCommand("insertText", text)
is essentially equivalent to typing out text
manually. Chrome (and, I guess, Firefox) seems to do a reflow on every ‘virtual keypress’
We can improve things significantly by only ‘typing out’ the text we actually need to replace:
discourse:main
← discourse:replace-text-perf
opened 02:01PM - 12 Sep 24 UTC
Followup to e25578d702791bac80b431acd450cc53b6c39a3c
Using execCommand to rep… lace the entire contents of the textarea is very slow for larger posts (it seems the browser does a reflow after every 'virtual keypress'.
This commit updates the `replaceText` function to be more surgical with its `insertAt` calls. Now it only selects & replaces the characters which are actually being replaced.
<!--
NOTE: All pull requests should have:
- Tests (rspec in Ruby, qunit in JavaScript). If no tests are included, please explain why.
- A descriptive title and description with context about the changes.
- Good commit messages with the correct prefixes, see: https://meta.discourse.org/t/-/19392
- When there are UX/UI changes, please add before/after screenshots, including mobile and desktop.
- For flakey tests, please describe the error you were having.
-->
4 Likes