Skip to content

Commit fe4a94f

Browse files
Merge #7994
7994: Speed up mbe matching in heavy recursive cases r=edwin0cheng a=edwin0cheng In some cases (e.g. #4186), mbe matching is very slow due to a lot of copy and allocation for bindings, this PR try to solve this problem by introduce a semi "link-list" approach for bindings building. I used this [test case](https://github.com/weiznich/minimal_example_for_rust_81262) (for `features(32-column-tables)`) to run following command to benchmark: ``` time rust-analyzer analysis-stats --load-output-dirs ./ ``` Before this PR : 2 mins After this PR: 3 seconds. However, for 64-column-tables cases, we still need 4 mins to complete. I will try to investigate in the following weeks. bors r+ Co-authored-by: Edwin Cheng <[email protected]>
2 parents 88f78bd + 9117148 commit fe4a94f

File tree

5 files changed

+270
-67
lines changed

5 files changed

+270
-67
lines changed

crates/hir_expand/src/db.rs

+2
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ fn parse_macro_with_arg(
340340
None => return ExpandResult { value: None, err: result.err },
341341
};
342342

343+
log::debug!("expanded = {}", tt.as_debug_string());
344+
343345
let fragment_kind = to_fragment_kind(db, macro_call_id);
344346

345347
let (parse, rev_token_map) = match mbe::token_tree_to_syntax_node(&tt, fragment_kind) {

crates/mbe/src/expander.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
mod matcher;
66
mod transcriber;
77

8-
use smallvec::SmallVec;
8+
use rustc_hash::FxHashMap;
99
use syntax::SmolStr;
1010

1111
use crate::{ExpandError, ExpandResult};
@@ -96,7 +96,7 @@ pub(crate) fn expand_rules(
9696
/// many is not a plain `usize`, but an `&[usize]`.
9797
#[derive(Debug, Default, Clone, PartialEq, Eq)]
9898
struct Bindings {
99-
inner: SmallVec<[(SmolStr, Binding); 4]>,
99+
inner: FxHashMap<SmolStr, Binding>,
100100
}
101101

102102
#[derive(Debug, Clone, PartialEq, Eq)]

0 commit comments

Comments
 (0)