##// END OF EJS Templates
dirstate-tree: Use HashMap instead of BTreeMap...
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

File last commit:

r41277:168041fa default
r47889:15395fd8 default
Show More
testing.rs
72 lines | 1.7 KiB | application/rls-services+xml | RustLexer
Georges Racinet
rust: factorized testing Graphs...
r41277 // testing.rs
//
// Copyright 2018 Georges Racinet <georges.racinet@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use crate::{Graph, GraphError, Revision, NULL_REVISION};
/// A stub `Graph`, same as the one from `test-ancestor.py`
///
/// o 13
/// |
/// | o 12
/// | |
/// | | o 11
/// | | |\
/// | | | | o 10
/// | | | | |
/// | o---+ | 9
/// | | | | |
/// o | | | | 8
/// / / / /
/// | | o | 7
/// | | | |
/// o---+ | 6
/// / / /
/// | | o 5
/// | |/
/// | o 4
/// | |
/// o | 3
/// | |
/// | o 2
/// |/
/// o 1
/// |
/// o 0
#[derive(Clone, Debug)]
pub struct SampleGraph;
impl Graph for SampleGraph {
fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
match rev {
0 => Ok([NULL_REVISION, NULL_REVISION]),
1 => Ok([0, NULL_REVISION]),
2 => Ok([1, NULL_REVISION]),
3 => Ok([1, NULL_REVISION]),
4 => Ok([2, NULL_REVISION]),
5 => Ok([4, NULL_REVISION]),
6 => Ok([4, NULL_REVISION]),
7 => Ok([4, NULL_REVISION]),
8 => Ok([NULL_REVISION, NULL_REVISION]),
9 => Ok([6, 7]),
10 => Ok([5, NULL_REVISION]),
11 => Ok([3, 7]),
12 => Ok([9, NULL_REVISION]),
13 => Ok([8, NULL_REVISION]),
r => Err(GraphError::ParentOutOfRange(r)),
}
}
}
// A Graph represented by a vector whose indices are revisions
// and values are parents of the revisions
pub type VecGraph = Vec<[Revision; 2]>;
impl Graph for VecGraph {
fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
Ok(self[rev as usize])
}
}