-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[nll] hash borrows in scope for better performance #53159
Comments
This should be a big win for html5ever -- |
Moving to RC 2 -- not a blocker. |
Removing from all milestones as this just doesn't release like a Rust 2018 blocker (perf is "good enough"). Marked as NLL-deferred. |
NLL premeeting triage. Unclear what priority to assign here, since it is not clear whether or not this would still be much of a win. (Its possible it might be; I just don't know.) Continuing to leave off a P-label; hopfeully I'll revisit next week with more information. |
I'm inclined to just close this issue, personally, although I guess the idea may still be actionable and relevant. |
NLL triage: closing. If we later decide that this idea has merit, we can reopen (or open a fresh issue, or just implement a PR). |
So I have an idea for how to improve performance in cases like html5ever where there are tons of borrows in scope at certain points. Right now, we have a pretty naive algorithm that implements over all borrows in scope:
rust/src/librustc_mir/borrow_check/path_utils.rs
Lines 40 to 52 in 18925de
I think we would do better if we stored the "borrows in scope" organized by the "root local" of the borrow:
rust/src/librustc_mir/borrow_check/place_ext.rs
Lines 20 to 23 in 18925de
In fact, I think we could do a "quick hack" to make this work. The
BorrowSet
already has an index of borrow indices based on their "root locals":rust/src/librustc_mir/borrow_check/borrow_set.rs
Lines 44 to 45 in 18925de
So what we can do is to modify
each_borrow_involving_path
. Instead of taking an iterator over borrows in scope, it would take some sort ofis_borrow_in_scope: impl Fn(BorrowIndex) -> bool
function. It would then find the root local (if any) of the access path, find all borrows that apply to that root local, and iterate over those, testing if each of them is in scope.We could make this more efficient in many ways -- e.g., using bitsets and things -- but this basic change should already eliminate some of the horrible
O(n^2)
behavior.The text was updated successfully, but these errors were encountered: