See Improving responsiveness in text inputs for an explanation of how to use JavaScript requestIdleCallback for improved browser responsiveness:
let queued = false textarea.addEventListener('input', () => { if (!queued) { queued = true requestIdleCallback(() => { updateUI(textarea.value) queued = false }) } })