comparison rust/hg-core/src/dirstate_tree/status.rs @ 47119:15395fd8ab28

dirstate-tree: Use HashMap instead of BTreeMap BTreeMap has the advantage of its "natural" iteration order being the one we need in the status algorithm. With HashMap however, iteration order is undefined so we need to allocate a Vec and sort it explicitly. Unfortunately many BTreeMap operations are slower than in HashMap, and skipping that extra allocation and sort is not enough to compensate. Switching to HashMap + sort makes `hg status` 17% faster in one test case, as measure with hyperfine: ``` Benchmark #1: ../hg2/hg status -R $REPO --config=experimental.dirstate-tree.in-memory=1 Time (mean ± σ): 765.0 ms ± 8.8 ms [User: 1.352 s, System: 0.747 s] Range (min … max): 751.8 ms … 778.7 ms 10 runs Benchmark #2: ./hg status -R $REPO --config=experimental.dirstate-tree.in-memory=1 Time (mean ± σ): 651.8 ms ± 9.9 ms [User: 1.251 s, System: 0.799 s] Range (min … max): 642.2 ms … 671.8 ms 10 runs Summary './hg status -R $REPO --config=experimental.dirstate-tree.in-memory=1' ran 1.17 ± 0.02 times faster than '../hg2/hg status -R $REPO --config=experimental.dirstate-tree.in-memory=1' ``` * ./hg is this revision * ../hg2/hg is its parent * $REPO is an old snapshot of mozilla-central Differential Revision: https://phab.mercurial-scm.org/D10553
author Simon Sapin <simon.sapin@octobus.net>
date Thu, 29 Apr 2021 11:32:57 +0200
parents c92e63762573
children ce41ee53263f
comparison
equal deleted inserted replaced
47118:c92e63762573 47119:15395fd8ab28
108 return; 108 return;
109 }; 109 };
110 110
111 // `merge_join_by` requires both its input iterators to be sorted: 111 // `merge_join_by` requires both its input iterators to be sorted:
112 112
113 // 113 let mut dirstate_nodes: Vec<_> = dirstate_nodes.iter_mut().collect();
114 // * `BTreeMap` iterates according to keys’ ordering by definition
115
116 // `sort_unstable_by_key` doesn’t allow keys borrowing from the value: 114 // `sort_unstable_by_key` doesn’t allow keys borrowing from the value:
117 // https://github.com/rust-lang/rust/issues/34162 115 // https://github.com/rust-lang/rust/issues/34162
116 dirstate_nodes
117 .sort_unstable_by(|(path1, _), (path2, _)| path1.cmp(path2));
118 fs_entries.sort_unstable_by(|e1, e2| e1.base_name.cmp(&e2.base_name)); 118 fs_entries.sort_unstable_by(|e1, e2| e1.base_name.cmp(&e2.base_name));
119 119
120 itertools::merge_join_by( 120 itertools::merge_join_by(
121 dirstate_nodes, 121 dirstate_nodes,
122 &fs_entries, 122 &fs_entries,