-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Search is too slow #5176
Comments
Hmm I am pretty sure that monaco makes use of an index - text data in editors tend to stay pretty stable normally beside the few lines the user is currently editing. So even more costly index creation is justified by a rather low change rate over time. The terminal buffer is not quite the same in that regard - it tends to change text data substantially over time, so the question is, if we can find a low cost index repr, which still can speed up the search significantly. I have lit. no clue about search addon, so idk how it currently approaches this issue. I prolly would check, if a trie / suffix array can help here, but those are typically quite expensive to create, so might be too much for fast changing data. If thats the case, maybe a lighter version only caching line & content position for the first n letters, then switching to line content eval is faster. How deep such an index cache should go, depends on the trie branching and the size of the position buckets, which is again data dependent (so there is no overall good solution for that). |
I don't think monaco has a particularly clever index as you're suggesting actually, just caching similar to us (I might be wrong). I think the performance problems mainly stem from the fact that neither of us really got too involved in the search addon and performance wasn't a big focus. Performance of registering so many decorations might be a part of this too, would need to investigate. |
Ah ok, well that was just a wild guess from my side. But if they do it likewise as the search addon currently, the perf difference might indeed result from another bottleneck and not the actual positional search. |
Did a few orientation perf tests with your test file to see, where we start from (scrollback set to 100k, searching the full file line count in one go with sync code just collecting buffer positions):
Seems the lower limit for naive search on the whole buffer is 50-100 ms with Javascript on my machine for your test file. While WASM typically shows a 2-5x speedup for those "chew on that big chunk of data" tasks, I dont expect it to be faster here due to the needed data copies, so I did not test it. Configuring the current code to also match all occurences takes currently ~6.3 s: xterm.js/addons/addon-search/src/SearchAddon.ts Lines 436 to 437 in a5fc111
Remember that those numbers cannot be directly compared (the current addon code does a lot more than just collecting buffer positions). It still gives some hints about the possible gains. Also I did not test any more clever caching, as the file is a flat repeat of the search string, so any branch cutting on lines wont apply at all. |
@Tyriar Did a bit more investigation - when I add the highlightAll part to my fast direct buffer search, things dont look good anymore, runtime for 72960 highlighted matches is now ~600 ms:
Tracing things further down, big portions of the overhead runtime come from:
To me it seems, that the vs event system is too heavy for fast marker creation. Also the results suggest, that the event impl is not specifically optimized for low GC profile: I'd suggest to re-eval the usage of vs/eventemitter for terminal markers. Idk if those could be made faster per se, the code looks quite convoluted to me and I guess thats for a reason. Maybe we dont need all the event fanciness for markers and can get away with a less complete but much faster impl instead. |
Currently the search addon limits itself to 1000 highlights by default. Contrast this to monaco's 20000 results before it gives up highlighting. When we increase our limit to 20000 the search itself ends up blocking the renderer pretty significantly.
Here is a profile using my i7-12700KF 3.61 GHz:
test file test.txt
Note that the search is also not incremental, so all successive searches take the same amount of time even for non-regex searches. #5177
VS Code issue: microsoft/vscode#230365
The text was updated successfully, but these errors were encountered: