rooks: useTimeout restart() method that does not cause a state update

Is your feature request related to a problem? Please describe. I’m setting a timeout as a result of a user action that saves to file in 2000 ms, that way, if multiple actions are performed in a small period, the disk doesn’t get thrashed. However, the state updates required to clear and start the timer are taking upwards of 50 ms. This causes noticeable sluggishness in the application, even though I’m only scheduling a save to eventually happen in the future.

Describe the solution you’d like Add a restart method to the returned object, that doesn’t cause any state updates if the timeout is already started.

Describe alternatives you’ve considered I’m going to have to stop using useTimeout now since it causes too much of a performance issue

Additional context Since this is serializing the state of a code editor, 50ms freezes are happening on scroll, on cursor movement, selection, etc. If a desktop application can’t even maintain 60fps then I don’t know what I’m doing with my life.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

I think I have a solution for this. I will get back in a day.

@LoganDark You can call the denounced callback when the user stops typing or on a button click or whenever.

That should do the job IMO.

Right, and now we’re back to the problem of “how do I know when the user is done typing”. I only get events on each key down. There’s no event for “there have been no keys down in the past couple seconds”. So I have to use a timeout.