codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.44k stars 343 forks source link

Built in browser search does not work for large documents #1383

Closed dyedgreen closed 1 month ago

dyedgreen commented 1 month ago

Describe the issue

I know that Codemirror uses partial rendering to improve performance on large documents.

I believe it also has a feature to temporarily disable this when a page is being printed (rendering the whole document and then redrawing the normal way in the next animation frame).

Would it be possible to do a similar thing when the user triggers the built in browser search?

Triggering on CTRL+F should be easy enough though I admit I can’t think of a good way to return to the partial render afterwards.

For our specific use case, the documents are also known to not change very frequently and are mostly not editable, which means we’re also okay with just drawing the full document all the time (I don’t think there is an option to do this currently though).

Browser and platform

No response

Reproduction link

No response

marijnh commented 1 month ago

No, that would be terrible for performance — searching is something a user can do repeatedly, and rendering out the entire document can be very expensive.

Support for full-document native search is not going to be doable until browsers provide a reasonable way for us to hook into that without rendering the entire document.

dyedgreen commented 1 month ago

Do you think it would be reasonable to have an option that disables the partial rendering for a given document? We have some views that change very rarely and so the performance tradeoff would be worth it in our case.

marijnh commented 1 month ago

The whole system is written to assume a bounded size on the rendered viewport. I'm not really prepared to make this an option and then deal with all the support requests from people who turn it on and unsurprisingly get awful performance (which was exactly how this thing turned out in version 5.x). You may consider rendering plain uneditable highlighted code for the views that don't change instead.