-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
Description
Throttling!
If your UI enables rapid user interaction & updates, then how do you prevent the server or the clientside JS from getting overloaded?
This has come up here and there over the years and we've solved pieces of this puzzle in different ways:
- When typing into a
dcc.Input
, users can prevent every single keypress from updating the callback by using buttons withState
or onblur
(tabbing or entering) withn_blur
&n_submit
- In serverside callbacks, if many requests are made at the same time for the same callback, then we'll prune out redundant requests while they're in the queue - Callback chain refactoring and performance improvements #1254
This still laves some use cases:
- What if you want to allow keypress updates, but just less frequently?
- What about clientside callbacks that don't get the same network request pruning in Callback chain refactoring and performance improvements #1254?
- What about components that don't have an equivalent of "blur" or "enter" and aren't well suited for buttons &
State
? LikehoverData
indcc.Graph
One idea is to solve this in the framework level with:
@app.callback(Output(...), [Input(...)], throttle=500)
This would be the second keyword argument into app.callback
. The first was introduced in 1.12.0 with prevent_initial_call=True
, see #1228
If any community member is interested in exploring this idea, then see:
- Prevent initial call #1228 for an example of how to wire callback keyword arguments from the backend up to the frontend
- https://github.com/plotly/dash/blob/dev/dash-renderer/src/observers/requestedCallbacks.ts for where callbacks are queued up for requests. Some throttling logic might go in here. See Callback chain refactoring and performance improvements #1254 for some context on the State Machine refactoring
- Contributing guide: https://github.com/plotly/dash/blob/dev/CONTRIBUTING.md
- After you've made a little progress, please submit a PR early to let us know that you are working on this
Alternatively, this work (and the rest of our work) can be funded by directly by organizations: https://plotly.com/products/consulting-and-oem or prioritized by Dash Enterprise customers.
joekrie, bchretien and frnhr