-
Notifications
You must be signed in to change notification settings - Fork 9
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
Optimize LineCache #15
Comments
It'd also be nice if |
Updating the cache is CPU bound task, so we cannot run it on the tokio event loop directly: it would block the loop at each update. If we want to make it asynchronous we could update the cache in a background thread for instance, send an event when it's ready, and re-draw when we see this event. I'm not sure this is something The best thing we could do at
Assuming the updates sent by the core are queued correctly, there's no way to apply an update partially or multiple updates at the same time thanks to the language's safety: the compiler will prevent you from mutating the cache in two places simultaneously (well unless you use a cell, but then you'd have a panic at runtime). |
For reference, here is how the cache update is done in xi-macs. I might be interesting to see if they have optimizations we don't: https://github.com/xi-editor/xi-mac/blob/d4ecbcad77928de8e60c7dd33dbb42da9a72a6f8/Sources/XiEditor/LineCache.swift#L103-L208 |
Oh, alright, wasn't sure how much Tokio's threadpool and handle and how expensive spawning a new thread is - but it seems like it's pretty cheap, so I guess I'll go with that.
Yup, I was more talking about this from a user's perspective: If the user inputs a I'll take a look at how xi-max does it, I suppose. I also don't think xrl should provide this. Although it's a very common thing to do every frontend needs to do different things to redraw and spawning a thread for the update isn't too hard. |
FWIW this was easy to implement in gxi, see Cogitri/Tau@9315fbe . Thanks for the pointer :) |
FWIW gxi's previous linecache seems to be very similiar to xi-mac's. I'll spin up some benchmarks of xrl with its current implementation and gxi's previous linecache in a bit. See: |
This is probably a very stupid question, as I have not really dug deep into xrl's code base, but currently the LineCache consists of a
There I miss a lot of lines in between, so the Vec-index doesn't help me at all and I have to look at each Line individually to check their associated line number. |
No worries, please do ask these kinds of questions, it's very nice to hear an "oursiders" questions to get different views of one's own work :)
Not all
I'm somewhat sure that the Vec-index should do the trick (and sort of automagically work around soft broken lines), but you're encountering a bug in xrl's linecache (see #15). Could you maybe try again with Tau's linecache, where this should work. When I have a bit more time I'll try to fix xrl's linecache and switch Tau over to that. In Tau I do the following during drawing:
As noted previously, the Vec-index should work for that, but you'll need a functioning index during normal operation too, otherwise scrolling can get veeeery weird (when lines aren't sorted correctly). |
As its not a drop in replacement, I would need to adjust a bunch of stuff, for which I currently have no time, unfortunately. If I understood that correctly, somehow I'm a bit afraid of the performance impact for very large files and big jumps (e.g. open a 200MB file and jump directly to the end of that file. Then tens of thousands of |
Ah, I think it's just replacing
Yup, it's not optimal but it works whereas xrl currently bugs out it seems. I'll try to look into xrl's linecache before I go on holidays - but I'm not quite positive here to get the line_num from for lines which are soft broken, since those don't have a line number. And what number should they have? They can't just have the same number, they mustn't have previous_number + 1 since you'd get wrong results then: line 238 We can't make that 238,239(actually 238),240(actually 238),241(actually 239) because then trying to work with line 239 wouldn't give correct results (e.g. when trying to measure its width) |
Currently the LineCache struct doesn't really simplify that much except applying an update when we receive one from xi. It was copied here from xi-term as is but i think we can do better.
I wont have time to work on this for a while I'm just Noting some stuff here so i can remember whenever i get back to it. But if anyone who stumbles by wants to take a crack at it be my guest PR's are always welcome.
This is harder than you would think(or i'm an idiot 😉 ), xi update's are seen as a function from old cache state to new, so figuring out exactly when a line number has changed is not as easy as it first seems.
As i think of more way's to improve the line cache over the next couple month's as i mess with xi-term, ill mark down any other optimizations that could be made here
The text was updated successfully, but these errors were encountered: