-
-
Notifications
You must be signed in to change notification settings - Fork 15k
[nll] hash borrows in scope for better performance #53159
Copy link
Copy link
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)NLL-performantWorking towards the "performance is good" goalWorking towards the "performance is good" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-compiler-performanceWorking group: Compiler PerformanceWorking group: Compiler Performance
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)NLL-performantWorking towards the "performance is good" goalWorking towards the "performance is good" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-compiler-performanceWorking group: Compiler PerformanceWorking group: Compiler Performance
Type
Fields
Give feedbackNo fields configured for issues without a type.
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
BorrowSetalready 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) -> boolfunction. 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.