-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix lag in Jupyter caused by CSS in _repr_html_
#5201
Fix lag in Jupyter caused by CSS in _repr_html_
#5201
Conversation
This seems to cause a major slowdown in notebooks with more than a couple of dozens of cells.
Thanks @SimonHeybrock ! Tagging @jsignell & @benbovy as the experts! |
I didn't manage to reproduce the lag, but this change seems totally reasonable to me! |
Thanks for the review @jsignell !
Can someone try out this PR in VS Code please? |
@SimonHeybrock would you be able to see whether running this with |
I don't have VS code so I can't try, but looking at the CSS I feel that this would actually break the colors there, since I moved the general settings from So I would recommend not to merge this unless someone is able to try it out. |
@SimonHeybrock, I am going to try this out in VS code and will report back how it goes. |
Here are two screenshots for two themes (using this PR): |
Thanks a lot @andersy005 That looks concerning enough we should fix before merging: @SimonHeybrock how would you feel about giving the vscode-dark a swing too? |
Ok, I tried, but got stuck: I can reproduce the issue in VScode. However, I cannot find a way to inspect the CSS in VScode's Jupyter console. The theme itself is a We somehow need to detect the theme within |
I am out of comfort zone with CSS & JS — but does |
Cheers, that was what I was looking for! |
Or not quite: The DOM seems to end at |
@fujiisoup added the vscode dark mode support, maybe he has ideas. |
Confirmed that this also breaks the darkmode also in google colab.
I did it in #4036 but this was actually a workaround and should be improved by an expert. |
This looks working with a darkmode, but I'm not sure if this solves the original problem. It looks to me that defining custom properties in |
It would be a shame to lose the benefits of this.
(* Did you know that research suggests we're either the same or slightly better at reading light mode?? Is dark mode LARPing?) |
Marked this as "plan to merge" — please comment if you think that's a bad tradeoff between performance and dark mode. |
I am trying to measure the performance of master, this PR and mine (which fixes this PR to be compatible with dark mode) but couldn't see any big difference in my environment. What I did in this experiment is to make a notebook with hundreds of empty cells with xarray under these branches. Maybe we may need more cells? css_render.mp4movie |
@fujiisoup Maybe I missed it in the video, but did you try if there are differences when running an individual cell, not just when loading the page the first time? My point is:
|
I tried to measure the performance However, I'm not very confident if this actually measures the css performance. @SimonHeybrock, do you have any suggestions how to measure the peformance? |
Indeed, such timings do not include the CSS timings. The only way I was able to see it was to use the Web Dev tools that come as part of Firefox or Chrome. You should be able to see the timings included there when recording a profile. |
Maybe can we measure the first-loading time?
Can you tell me more about this? I'll try to reproduce and measure the performance. repr.mp4 |
I think this is also a problem, but I believe this is independent and not improved by the CSS changes in this branch. Maybe a Jupyter issue and not related to libraries in use?
So I had used Chrome, open "Developer Tools" > "Performance" tab:
I think I had observed a difference in the "Render" part of the profile, but I cannot check now (I may be able later today when I am back to my main computer). |
I see. Indeed, I didn't see any significant difference among branches.
I tried but I think maybe better to wait for your update. |
Here are some profiling results on my laptop (MacOS 11.2, MacBook Pro 13-inch, 2019). versions: chrome: 91.0.4472.114 The results below only show the refresh of the ouput cell when I re-execute it (I used the screenshots in chrome's web developer tools to manually set the time span of interest on the profiling timeline). I've also measured the rendering of a very basic pandas dataframe using import xarray as xr
import numpy as np
import pandas as pd
data = np.random.rand(4)
a = xr.DataArray(data, coords=[np.arange(4)], dims=['x'])
df = pd.DataFrame({'col': data}) pandas / no additional cellpandas / many empty cellsxarray / no additional cellxarray / many empty cellsSo it seems to me that it's more a Jupyter notebook issue. The decrease in performance (rendering time) scales pretty much the same for pandas and xarray reprs. |
Closing as upstream issue |
What
The CSS used by
_repr_html_
(for displaying objects in Jupyter) placed font colors in:root
as CSS custom properties. This seems to cause lag in notebooks with more than a couple of dozens of cells when running a cell that displays outputs. We observed this on Chrome and Firefox, so it is probably not browser-specific.To reproduce
a
:a
Fix
:root
but the top-level classxr-wrap
.vscode-dark
settings also may need to change, but my understanding of CSS is too limited. Can someone suggest how to fix this or take care of it?Discussion
Interestingly we ran into this problem independently of xarray: While
scipp
borrowed an early draft ofxarrays
's_repr_html_
implementation (thanks!), this was before the color configs were placed into:root
--- we just happened to add such a color config independently. Since this was a recent change we managed to find the culprit yesterday (scipp/scipp#1847). And then it occurred to me to check whether xarray has the same problem...So this makes me think that other projects that define
_repr_html_
may well suffer from the same problem. Can we do anything to spread the word, or better, could there be a way to fix this for everyone (in Jupyter)?Checklist
pre-commit run --all-files
whats-new.rst