Form inputs show excessive keyboard input lag when plotly charts onscreen
See original GitHub issueSummary
Plotly graphs on screen cause very bad input lag (i.e the text in the form is long after the keystroke) for forms.
Steps to reproduce
A fairly minimal reproduction is in this repo along with a screen recording.
The demo app is deployed on streamlit.io so anyone can see the performance issue for themselves. The issue doesn’t happen with Altair charts.
If applicable, please provide the steps we should take to reproduce the bug:
Expected behavior:
Text input or numeric input in the form should be nearly instant and not subject to lag.
Actual behavior:
Text or numeric input shows up in the form input fields 300ms or more after the key is pressed.
Is this a regression?
Not sure
Debug info
- Streamlit version: (get it with
$ streamlit version
) 1.12.2 - Python version: (get it with
$ python --version
) 3.9 - Using Conda? PipEnv? PyEnv? Pex? pip
- OS version: OS X
- Browser version: Safari or Chrome
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7
Top Results From Across the Web
High cpu usage when typing in text fields with plotly graphs on ...
I'm seeing very high cpu usage for keystrokes in text fields just when plotly graphs are on screen in a web browser.
Read more >Keyboard latency | Hacker News
Key travel time is itself a form of latency, distinct from throughput because it doesn't count the time you take to move your...
Read more >python - Interactive large plot with ~20 million sample points ...
So your data isn't that big, and the fact that you're having trouble plotting it points to issues with the tools. Matplotlib has...
Read more >mikolalysenko - 0 FPS
Some databases implement mechanisms like “BULK INSERT” for sequentially inserting elements into a B-tree to avoid the performance degradation caused by many ...
Read more >plotly Changelog - PyUp.io
Display the version of plotly.js when hovering over the modebar ... When a trace is added to a standard `Figure` graph object the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m pretty sure I figured out the cause of the issue. Widgets in forms update the stored state very eagerly, causing a top level component to rerender each input. The plotly component we’re using wants to use reference identity to determine if it should recompute things for a rerender, but we keep passing it objects that are value-equal but not reference-equal, so it does a bunch of work because it always thinks things have changed. This doesn’t cause lag for a text box out of a form because it only updates the stored state at the very end, at which point it’s easy to miss the app spending time doing plotly stuff because it is also processing the results of the rerun that just started.
Fixing this will be a matter of either changing what we pass to the component, or replacing it with one that works differently. I don’t know when exactly I’ll get to fixing it but there’s a clear path for it, at least.
I took a look at this issue this afternoon, something about forms is causing DOM events to trigger plotly to run an expensive rerender, though I don’t yet know why.