-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
map positions through changes in O(N) #7408
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! I haven't taken a close look yet, but at first glance, it unfortunately seems to squarely conflict with #7269, which relies on the fact that each range is mapped individually. 🤔 Hopefully there's an alternative I can do.
I hadn't reviewed that PR yet but I took a look and don't really think it conflicts. You are only mapping ranges trough a changeset with a single change (and do the offset tracking yourself so it's already O(N)). I deleted This PR doesn't really remove anything. It basically just changes |
Hm, yeah, I think you're right, other than |
Yeah this only affect commands which don't manually update the transaction (also diagnostic mapping and virtual text mapping). It does however affect the "default" codepath of Our two PRs are kind of similar in that you have also included a more efficent implementation of mapping selections trough transaction by accident (by storing an offset and calling map on a single element change set). Your PR also optimizes the This PR is still useful for diagnostic/virtual text mapping and quite a few commands that still use automatic mapping. The automatic mapping is also always used for all commands for views that aren't the current view (so the selection you supply only applies to the current view). In fact the code is currently a bit unoptimized and always performs the automatic for the current view too and later just overwrites with the manually supplied selection. |
This has made me realize that I think we're unnecessarily mapping the whole selection through the change set in the cases where the transaction explicitly specifies a new one. helix/helix-view/src/document.rs Lines 1070 to 1085 in 18160a6
We essentially do that whole mapping and then immediately throw all that work away. |
The mapping still needs to happen for other views than the current one. We could speed things up slightly by removing the current view's selection from the selection set before doing the mapping if the transaction contains a selection |
2efb508
to
85dd01b
Compare
I fixed a small oversight that was causing test failures and addressed the comments. Should be ready now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍓🫐🥞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some typos :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some very minor comments but otherwise this looks great, nice work!
@@ -420,6 +420,7 @@ pub mod util { | |||
return transaction; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain/add a comment why normalize isn't needed here? This is an additional invariant that we should document in places where no_normalize is used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment but this was actually exiting behaviour. Really this isn't a selection we produce here at all, we need the mapped ranges for calculating the actual selecton below (which is normalized later). In the past I achieved that by calling `map_pos' on the ranges directly (below). Normalizing here not only has no point it would also break the association between tabstops and selections (if selections are merged/sorted). I just switched to the selection function here to also take advantage of the optimization here but really this is not a selection at all we are just updating a list of ranges.
d0b96e0
to
5755c92
Compare
5755c92
to
78fe22e
Compare
Closes #7396
Previously we iterated the entire changset for every position we mapped through the changes. That made the mapping
O(MN)
when mapping multiple positions andO(N^2)
for most mutlicursor operations but since we are basically always dealing with sorted lists we can do the two iterations in lockstep which allowsO(M+N)
mappingWith this PR the example from #7396 now is pretty usable and the mapping doesn't show up in the flamegraph anymore