Mercurial > public > mercurial-scm > hg
view rust/hg-core/src/lib.rs @ 44386:8f7c6656ac79
rust-nodemap: pure Rust example
To run, use `cargo run --release --example nodemap`
This demonstrates that simple scenarios entirely written
in Rust can content themselves with `NodeTree<T>`.
The example mmaps both the nodemap file and the changelog index.
We had of course to include an implementation of `RevlogIndex`
directly, which isn't much at this stage. It felt a bit
prematurate to include it in the lib.
Here are some first performance measurements, obtained with
this example, on a clone of mozilla-central with 440000
changesets:
(create) Nodemap constructed in RAM in 153.638305ms
(query CAE63161B68962) found in 22.362us: Ok(Some(269489))
(bench) Did 3 queries in 36.418?s (mean 12.139?s)
(bench) Did 50 queries in 184.318?s (mean 3.686?s)
(bench) Did 100000 queries in 31.053461ms (mean 310ns)
To be fair, even between bench runs, results tend to depend whether
the file is still in kernel caches, and it's not so easy to
get back to a real cold start. The worst we've seen was in the
50us ballpark.
In any busy server setting, the pages would always be in RAM.
We hope it's good enough not to be significantly slower on any
concrete Mercurial operation than the C nodetree when fully in RAM,
and of course this implementation has the serious headstart advantage
of persistence.
Differential Revision: https://phab.mercurial-scm.org/D7797
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Tue, 18 Feb 2020 19:11:15 +0100 |
parents | d8d4fa9a7f18 |
children | 52d40f8fb82d |
line wrap: on
line source
// Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net> // and Mercurial contributors // // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. mod ancestors; pub mod dagops; pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; mod dirstate; pub mod discovery; pub mod testing; // unconditionally built, for use from integration tests pub use dirstate::{ dirs_multiset::{DirsMultiset, DirsMultisetIter}, dirstate_map::DirstateMap, parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE}, status::{status, StatusResult}, CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState, StateMap, StateMapIter, }; mod filepatterns; pub mod matchers; pub mod revlog; pub use revlog::*; #[cfg(feature = "with-re2")] pub mod re2; pub mod utils; use crate::utils::hg_path::{HgPathBuf, HgPathError}; pub use filepatterns::{ parse_pattern_syntax, read_pattern_file, IgnorePattern, PatternFileWarning, PatternSyntax, }; use std::collections::HashMap; use twox_hash::RandomXxHashBuilder64; pub type LineNumber = usize; /// Rust's default hasher is too slow because it tries to prevent collision /// attacks. We are not concerned about those: if an ill-minded person has /// write access to your repository, you have other issues. pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>; #[derive(Clone, Debug, PartialEq)] pub enum DirstateParseError { TooLittleData, Overflow, CorruptedEntry(String), Damaged, } impl From<std::io::Error> for DirstateParseError { fn from(e: std::io::Error) -> Self { DirstateParseError::CorruptedEntry(e.to_string()) } } impl ToString for DirstateParseError { fn to_string(&self) -> String { use crate::DirstateParseError::*; match self { TooLittleData => "Too little data for dirstate.".to_string(), Overflow => "Overflow in dirstate.".to_string(), CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e), Damaged => "Dirstate appears to be damaged.".to_string(), } } } #[derive(Debug, PartialEq)] pub enum DirstatePackError { CorruptedEntry(String), CorruptedParent, BadSize(usize, usize), } impl From<std::io::Error> for DirstatePackError { fn from(e: std::io::Error) -> Self { DirstatePackError::CorruptedEntry(e.to_string()) } } #[derive(Debug, PartialEq)] pub enum DirstateMapError { PathNotFound(HgPathBuf), EmptyPath, InvalidPath(HgPathError), } impl ToString for DirstateMapError { fn to_string(&self) -> String { match self { DirstateMapError::PathNotFound(_) => { "expected a value, found none".to_string() } DirstateMapError::EmptyPath => "Overflow in dirstate.".to_string(), DirstateMapError::InvalidPath(e) => e.to_string(), } } } pub enum DirstateError { Parse(DirstateParseError), Pack(DirstatePackError), Map(DirstateMapError), IO(std::io::Error), } impl From<DirstateParseError> for DirstateError { fn from(e: DirstateParseError) -> Self { DirstateError::Parse(e) } } impl From<DirstatePackError> for DirstateError { fn from(e: DirstatePackError) -> Self { DirstateError::Pack(e) } } #[derive(Debug)] pub enum PatternError { Path(HgPathError), UnsupportedSyntax(String), UnsupportedSyntaxInFile(String, String, usize), TooLong(usize), IO(std::io::Error), /// Needed a pattern that can be turned into a regex but got one that /// can't. This should only happen through programmer error. NonRegexPattern(IgnorePattern), } impl ToString for PatternError { fn to_string(&self) -> String { match self { PatternError::UnsupportedSyntax(syntax) => { format!("Unsupported syntax {}", syntax) } PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => { format!( "{}:{}: unsupported syntax {}", file_path, line, syntax ) } PatternError::TooLong(size) => { format!("matcher pattern is too long ({} bytes)", size) } PatternError::IO(e) => e.to_string(), PatternError::Path(e) => e.to_string(), PatternError::NonRegexPattern(pattern) => { format!("'{:?}' cannot be turned into a regex", pattern) } } } } impl From<DirstateMapError> for DirstateError { fn from(e: DirstateMapError) -> Self { DirstateError::Map(e) } } impl From<std::io::Error> for DirstateError { fn from(e: std::io::Error) -> Self { DirstateError::IO(e) } } impl From<std::io::Error> for PatternError { fn from(e: std::io::Error) -> Self { PatternError::IO(e) } } impl From<HgPathError> for PatternError { fn from(e: HgPathError) -> Self { PatternError::Path(e) } }