-
-
Notifications
You must be signed in to change notification settings - Fork 376
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
Potential Performance Regression #1445
Comments
I tested with some other versions of @codemirror/view (going back to 6.17.0) and I'm not seeing a noticeable difference in speed. I wasn't able to reproduce the stack overflow but I can see how it'll happen (the interface for But yeah, browser aren't great with huge amounts of inline elements. The time seems mostly spent in layout. To mitigate this, I guess one approach would be to allow |
If there is a way to only create decorators for the elements visible on screen, that would solve the issue. We would still want decorators to be created if the line is being wrapped and fills up the viewport. If that's not possible, simply limiting the amount of decorators created at once would be better than nothing. |
FIX: Improve performance of documents displaying lots of highlighted spaces by using a CSS background instead of pseudo-element. Issue codemirror/dev#1445
This is pretty much what CodeMirror's viewport system is for. But it creates a certain overlap, covering more than the currently visible area, in order to avoid blank space from popping into view during scrolling, and to not have to mess with the dom every time the editor is scrolled a few pixels. The amount content that the editor draws is usually something that browsers can lay out very quickly. Looking into this some more, it seems that even with the ~11k in-viewport tokens your example produces, I am getting okay performance when I do this locally (and, again, never hit the stack overflow). But on regex101, the performance is a lot worse. So maybe there is some other complicating factor. One thing I did notice is that the way I style these matters—with a |
Interesting, thanks for the update. I've debugged this a bit now over my lunch, and I'm consistently getting the stack overflow error in my local environment, but very rarely in production. Not sure what causes that distinction to occur. I did not know there was a built in extension for this. I will certainly use that instead. I can see that the plugin source is very similar to my code above, both lack Is there a way to safeguard from the stackoverflow? Perhaps setting an upper limit to avoid hitting this edge case. Alternatively, split the array up in chunks that can be processed independently. |
I've been thinking about having a custom implementation of |
Understood.
I think you can get the best of both worlds by checking the size of the array being manipulated, something like: if (arr.length > TROUBLESOME_SIZE) { safeSplice(...); }
else { regularSplice(...) } I'd be happy to test it out in my local environment. |
FIX: Avoid a stack overflow that could happen when updating a line with a lot of text tokens. Issue codemirror/dev#1445
Could you see if attached patch helps for the case where you're seeing these overflows? |
Patch fixes the stack overflow issue. Performance still seems pretty terrible, so much so that my browser locks up for a few seconds when interacting with the document. I can see from the DOM tree that every single element around a space is being rendered, even if it's well outside of the viewport. Could this issue be related to the fact that it's one long line of text and that line, at least parts of it, is inside the viewport? |
If you compare |
I understand that, but what I'm struggling to understand, do you render all the tokens in the visible lines, or only the tokens visible within the lines? Because this scenario has a line with 10k+ characters, but we can only see a few percent of those at a time. |
Long lines will be rendered only partially (hence the difference in DOM text length and document length). |
Gotcha, I can see that now. Seems like it renders a lot more than I would have thought. Thank you for your help, I'll have to troubleshoot the performance issues a bit more on my end, as I can't quite figure out why its so slow. |
Any chance you could tag a release with the splice fix? |
Yes—I've tagged 6.34.1 |
Describe the issue
I'm seeing a new bug on regex101 that results in errors sometimes being thrown to the console:
This seems to be related to the usage of the "Visualize Whitespace" setting (enabled by default) that the site offers. Without it, performance is snappy.
Here is the code:
I am aware that this is going to cause some performance issues, since each space/tab is being encapsulated in a tag, but it didn't use to be this slow, nor did the error appear in the console.
Using these versions:
Browser and platform
Chrome 128
Reproduction link
https://regex101.com/r/iMcJgo/1
The text was updated successfully, but these errors were encountered: