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

events: explore using getCoalescedEvents #5554

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mimecuvalo
Copy link
Member

Wanted to open a discussion on getCoalescedEvents and see if it's worth integrating into the canvas. The videos below show trying to draw with a CPU 20x slowdown.

(I know we've talked about getPredictedEvents but that's a separate topic)
Testbed: https://patrickhlauke.github.io/touch/coalesced-predicted-events/

Before:

Kapture.2025-03-04.at.17.07.35.mp4

After:

Kapture.2025-03-04.at.17.09.11.mp4

Change type

  • bugfix
  • improvement
  • feature
  • api
  • other

Release notes

  • Improve draw fluidity on slower CPUs by using getCoalescedEvents.

Copy link

vercel bot commented Mar 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
examples ✅ Ready (Inspect) Visit Preview Mar 11, 2025 11:28am
1 Skipped Deployment
Name Status Preview Updated (UTC)
tldraw-docs ⬜️ Ignored (Inspect) Visit Preview Mar 11, 2025 11:28am

@huppy-bot huppy-bot bot added the improvement Product improvement label Mar 4, 2025
@SomeHats
Copy link
Contributor

SomeHats commented Mar 4, 2025

this is so fucking cool??????

@SomeHats
Copy link
Contributor

SomeHats commented Mar 5, 2025

so, thinking about this a bit more... do we know of a reason we shouldn't do this?

@mimecuvalo
Copy link
Member Author

so, thinking about this a bit more... do we know of a reason we shouldn't do this?

There could be a hesititation around when there's a lot of shapes being manipulated, say, selecting a lot of shapes on the canvas and moving them around all at once, maybe that affects perf? @MitjaBezensek wdyt?

Or, well, say using the Hand tool and doing the same, moving the canvas around.

@MitjaBezensek
Copy link
Contributor

MitjaBezensek commented Mar 5, 2025

I think this definitely makes sense for events where high precision brings some benefits - like while drawing since it allows us to make drawings that more closely follow the user's input. For other cases it might actually be worse. The fact that browser coalesces events means that it determined the the device is not capable enough to process all of them, so it starts coalescing them.

We did run into some problems when we tried something like this before, see this PR, especially the coalescing part:
#3223

@mimecuvalo
Copy link
Member Author

We did run into some problems when we tried something like this before

Let's dig into that a bit , specifically, in the PR you reference it says:

Often a state node required information from elsewhere in the app when processing an event (such as camera position or page point, which is derived from the camera position)

  • Was that only an issue for things like resize? Or did it also affect drawing?
  • I'm also wondering if that was maybe particular to the custom coalescing that was happening vs. this native browser coalescing that we're just putting in the dispatch queue.
  • wdyt if we were to only look at getCoalescedEvents when we're specifically in the draw/highlight tools?

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

Successfully merging this pull request may close these issues.

3 participants