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
Line Numbers resize event going crazy when scrolling on mobile, freezing screen for more than a second #2123
Comments
I do not have enough knowledge of why use this event, but in my setup (core + line numbers) is working fine without this event. Resizing or not the screen, I do not have dynamic stuff being loaded, and if I had, I would call to highlight only that part. My pre code have this style:
I couldn't find a reason for this event, unless another plugin depend on it, and if this the case, would be a a wise to enable this event only when the other plugin is in use to avoid serious performance degradation on mobile. |
The thing I find surprising here is that the listener fires while you're scrolling... What browser are you using? And what phone/device is it on? |
iPhone 6s, safari |
may be related to this: https://stackoverflow.com/a/27966414/2391290 |
That question is for mobile Chrome. I did find this one tho: https://stackoverflow.com/questions/8898412/iphone-ipad-triggering-unexpected-resize-events/24212316 Answer suggests caching the current element size and only rerunning if it changes. Another answer suggests adding the viewport |
meta tag does not solve, mine is responsive design, that solution needs width set on the meta tag. But, anyway, for what purpose that resize event is for? because is working fine when removing that event. |
I didn't write the code myself, but my assumption is it's needed to ensure the line number stay aligned as the browser resizes, which is relevant if you rotate the phone (for mobile) or resize the browser (for desktop). |
Line numbers stay aligned without that event, during resize, rotate, refresh if:
If |
No, it doesn't. I just tested this on the plugin page (aka. I resized it with the event disabled) and expectedly it didn't work because of how Line Number works. But I do agree that the massive performance hit is not justified for such a simple plugin. The main problem is that the layout of the page is calculated for every line to get the height of each line. |
Assuming a monospace font, we know that a line doesn't have any breaks if it has <= characters compared to the longest line without breaks. I believe this is the best we can do and it's largely ineffective for small screens... |
I made a test page with 6 code blocks and did a few tests: Current approach: 3s The "batch per element" works by wrapping all each code lines with an element, appending all elements to the current sizer and then getting the height of all lines. Like this, all The "batch all elements" take this to the extreme and batches all elements together, so that the layout has to be calculated only once. But this is still not optimal as a full layout calculation for the whole page actually takes 80ms. So there's room for further optimization but it's 10x faster already. |
That is good news, faster is better. I will try to get a combination of CSS that I'm using that does not need lines being re aligned, just need on load and nothing else after. Things just stay in place on resize or orientation change without any other interaction. |
I have changed all units from
No other code for pre and code is applied. In this case, my layout does not need to be recalculated. On resize or orientation change or zooming. |
For this context I think |
How does your layout not change under a resize? You only set a |
with that css,
there is no need to have
line numbers stay in place, aligned. |
anyway, safari, maybe other browser too, trigger resize on mobile a lot, during scroll because of the hide bar or simple shrink it, and that is why if is going to listen on
something like this:
but in my case, if I'm going to deploy on production, i will fork prismjs, comment out this event, and handle that only with plain CSS, and that what is working for me. |
I don't whether want to do this because some people like to use |
the performance degradation on mobile using this approach (listen on 'resize'), this should be an alternative, not the default... anyway, going to implement by my self something that does not kill the performance on mobile, just because someone may be using |
With the But you're right. We should do this optimization. The problem is that we can't detect which units are used using |
I added it to #2125 but it will default to |
Information:
pre>code
highlighted.Description
This line:
It is firing aggressively on mobile (Real, !emulated) browser scroll events, freezing the screen for a few seconds. Without this event listener, scrolling became smooth again, but sometimes because of the large DOM I can see some lag when scrolling up and down, but not so bad like with this event listener.
With event listener 'resize':
With/without web workers the rendering lag is crazy long. At least with web workers I was able to scroll, couldn't see anything because of the slow rendering, but was able to scroll.
Without event listener 'resize':
With/without web workers there was no difference on the smoothness of scrolling.
Why this event?
The text was updated successfully, but these errors were encountered: