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

Replace input debouncing with a more robust mechanism for de-duplicating queued user events #206

Closed
wants to merge 1 commit into from

Conversation

wwwillchen
Copy link
Collaborator

@wwwillchen wwwillchen commented May 9, 2024

Fixes #171

@wwwillchen wwwillchen changed the title Replace input debouncing with a more robust mechanism for de-duplicat… Replace input debouncing with a more robust mechanism for de-duplicating queued user events May 9, 2024
@wwwillchen wwwillchen requested a review from richard-to May 9, 2024 22:25
mesop/server/server.py Outdated Show resolved Hide resolved
mesop/web/src/services/channel.ts Outdated Show resolved Hide resolved
mesop/web/src/services/channel.ts Show resolved Hide resolved
@wwwillchen wwwillchen force-pushed the i171 branch 2 times, most recently from 39cf4b3 to badcffc Compare May 11, 2024 05:31
@wwwillchen
Copy link
Collaborator Author

I'm actually not sure if this is the right approach now.

Consider the following sequence:

  1. user types "a" into input component (user event immediately sent)
  2. user types "bc" into input
  3. user clicks
  4. user types "d"

With my logic, it's possible that when the user event for click is processed, the state will only be "a" because "bc" have been dropped by the user event for "d".

To avoid this issue, we would need to change the algorithm so that we only drop "mergeable" user events (i.e. input events) from the oldest events until we hit a non-mergeable event.

To be honest, I'm wondering if I over-engineered this because I've never actually had someone complain about this race condition before and since I lowered it to 150ms, it's quite improbable in the status quo implementation to hit a race condition (e.g. type in an input and then click a button in less than 150ms).

@richard-to
Copy link
Collaborator

I'm actually not sure if this is the right approach now.

Consider the following sequence:

  1. user types "a" into input component (user event immediately sent)
  2. user types "bc" into input
  3. user clicks
  4. user types "d"

With my logic, it's possible that when the user event for click is processed, the state will only be "a" because "bc" have been dropped by the user event for "d".

To avoid this issue, we would need to change the algorithm so that we only drop "mergeable" user events (i.e. input events) from the oldest events until we hit a non-mergeable event.

To be honest, I'm wondering if I over-engineered this because I've never actually had someone complain about this race condition before and since I lowered it to 150ms, it's quite improbable in the status quo implementation to hit a race condition (e.g. type in an input and then click a button in less than 150ms).

Yeah that's a good point. So you're saying what potentially could happen is this:

While "a" is being processed by the server, the following events "bc", "click" + "d" happen.

Since these three events get queued up waiting for "a", "bc" gets dropped due to "d"

And you end up with the following events queued: "click", "d"

That does seem worrisome.

In terms of the current debouncing, I agree at 150ms, it would be hard to hit that race condition. I think the only time I've run into that issue is on the CI tests for chat which isn't realistic.

@wwwillchen
Copy link
Collaborator Author

I thought about this some more and a different approach we could do is the essentially send a batch of user events together. For example, whatever is queued, we'll send all of the user events together and process each one (in-order).

In theory, we can optimize this by doing 1 trace mode render loop, call all the event handlers and then do a final render loop if the render loop is mutation free.

I'll close this PR for now and re-open it once we get a clearer signal that the current approach has issues.

@wwwillchen wwwillchen closed this May 15, 2024
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.

Fix input/textarea debouncing logic
2 participants