Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize typing a single character #1233

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Janpot
Copy link

@Janpot Janpot commented Sep 17, 2024

What:

This improves performance of typing a single character by ~2x

Why:

Users complain about performance #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
  • Ready to be merged

I don't believe documentation/tests would be required here.

Copy link

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.

@ph-fritsche
Copy link
Member

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?

Comment on lines +3 to +8
export async function wait(config: Instance['config']): Promise<void> {
const delay = config.delay
if (typeof delay !== 'number') {
return
}
return Promise.all([
await Promise.all([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the function return Promise<undefined> instead of undefined for delay: null and results in await wait() to add a new micro task.
Are we sure this has no effect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants