Optimize typing a single character
What:
This improves performance of typing a single character by ~2x
Why:
Users complain about performance https://github.com/testing-library/user-event/issues/577. Also related to this thread
How:
The desired behavior is to (I suppose) yield to the next macrotask in between keyboard actions. We can avoid the initial wait. Some quick benchmarking suggested those wait calls make up the bulk of the runtime of this function. When there is only 1 action to run, this brings the wait calls from 2 => 1
Checklist:
- [ ] Documentation
- [ ] Tests
- [x] Ready to be merged
I don't believe documentation/tests would be required here.
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
The initial wait ensures that micro tasks added during (re)render are done before we dispatch events or manipulate the DOM.
Could you verify that resolving the promise on a new event loop step carries that performance hit?
Or is this just caused by other tasks that run in between? Wouldn't these other tasks run afterwards if we remove the setTimeout call and result in about the same overall execution time?