##// END OF EJS Templates
nodemap: introduce an option to use mmap to read the nodemap mapping...
nodemap: introduce an option to use mmap to read the nodemap mapping The performance and memory benefit is much greater if we don't have to copy all the data in memory for each information. So we introduce an option (on by default) to read the data using mmap. This changeset is the last one definition the API for index support nodemap data. (they have to be able to use the mmaping). Below are some benchmark comparing the best we currently have in 5.3 with the final step of this series (using the persistent nodemap implementation in Rust). The benchmark run `hg perfindex` with various revset and the following variants: Before: * do not use the persistent nodemap * use the CPython implementation of the index for nodemap * use mmapping of the changelog index After: * use the MixedIndex Rust code, with the NodeTree object for nodemap access (still in review) * use the persistent nodemap data from disk * access the persistent nodemap data through mmap * use mmapping of the changelog index The persistent nodemap greatly speed up most operation on very large repositories. Some of the previously very fast lookup end up a bit slower because the persistent nodemap has to be setup. However the absolute slowdown is very small and won't matters in the big picture. Here are some numbers (in seconds) for the reference copy of mozilla-try: Revset Before After abs-change speedup -10000: 0.004622 0.005532 0.000910 × 0.83 -10: 0.000050 0.000132 0.000082 × 0.37 tip 0.000052 0.000085 0.000033 × 0.61 0 + (-10000:) 0.028222 0.005337 -0.022885 × 5.29 0 0.023521 0.000084 -0.023437 × 280.01 (-10000:) + 0 0.235539 0.005308 -0.230231 × 44.37 (-10:) + :9 0.232883 0.000180 -0.232703 ×1293.79 (-10000:) + (:99) 0.238735 0.005358 -0.233377 × 44.55 :99 + (-10000:) 0.317942 0.005593 -0.312349 × 56.84 :9 + (-10:) 0.313372 0.000179 -0.313193 ×1750.68 :9 0.316450 0.000143 -0.316307 ×2212.93 On smaller repositories, the cost of nodemap related operation is not as big, so the win is much more modest. Yet it helps shaving a handful of millisecond here and there. Here are some numbers (in seconds) for the reference copy of mercurial: Revset Before After abs-change speedup -10: 0.000065 0.000097 0.000032 × 0.67 tip 0.000063 0.000078 0.000015 × 0.80 0 0.000561 0.000079 -0.000482 × 7.10 -10000: 0.004609 0.003648 -0.000961 × 1.26 0 + (-10000:) 0.005023 0.003715 -0.001307 × 1.35 (-10:) + :9 0.002187 0.000108 -0.002079 ×20.25 (-10000:) + 0 0.006252 0.003716 -0.002536 × 1.68 (-10000:) + (:99) 0.006367 0.003707 -0.002660 × 1.71 :9 + (-10:) 0.003846 0.000110 -0.003736 ×34.96 :9 0.003854 0.000099 -0.003755 ×38.92 :99 + (-10000:) 0.007644 0.003778 -0.003866 × 2.02 Differential Revision: https://phab.mercurial-scm.org/D7894

File last commit:

r44398:f98f0e3d default
r44843:f7459da7 default
Show More
discovery.rs
161 lines | 5.7 KiB | application/rls-services+xml | RustLexer
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 // discovery.rs
//
// Copyright 2018 Georges Racinet <gracinet@anybox.fr>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
//! Bindings for the `hg::discovery` module provided by the
//! `hg-core` crate. From Python, this will be seen as `rustext.discovery`
//!
//! # Classes visible from Python:
//! - [`PartialDiscover`] is the Rust implementation of
//! `mercurial.setdiscovery.partialdiscovery`.
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 use crate::{
Georges Racinet
rust-cpython: removed now useless py_set() conversion...
r43563 cindex::Index, conversion::rev_pyiter_collect, exceptions::GraphError,
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 };
Georges Racinet
rust-discovery: implementing and exposing stats()...
r42357 use cpython::{
Georges Racinet
rust-discovery: exposing sampling to python...
r42967 ObjectProtocol, PyDict, PyModule, PyObject, PyResult, PyTuple, Python,
Georges Racinet
rust-python3: compatibility fix for integer conversion...
r42519 PythonObject, ToPyObject,
Georges Racinet
rust-discovery: implementing and exposing stats()...
r42357 };
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 use hg::discovery::PartialDiscovery as CorePartialDiscovery;
use hg::Revision;
Georges Racinet
rust-cpython: removed now useless py_set() conversion...
r43563 use std::collections::HashSet;
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356
use std::cell::RefCell;
rust-index: add a function to convert PyObject index for hg-core...
r44398 use crate::revlog::pyindex_to_graph;
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 py_class!(pub class PartialDiscovery |py| {
data inner: RefCell<Box<CorePartialDiscovery<Index>>>;
Georges Racinet
rust-discovery: accept the new 'respectsize' init arg...
r42963 // `_respectsize` is currently only here to replicate the Python API and
// will be used in future patches inside methods that are yet to be
// implemented.
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 def __new__(
_cls,
Georges Racinet
rust-discovery: read the index from a repo passed at init...
r42964 repo: PyObject,
Georges Racinet
rust-discovery: accept the new 'respectsize' init arg...
r42963 targetheads: PyObject,
Georges Racinet
rust-discovery: optionally don't randomize at all, for tests...
r42968 respectsize: bool,
randomize: bool = true
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 ) -> PyResult<PartialDiscovery> {
Georges Racinet
rust-discovery: read the index from a repo passed at init...
r42964 let index = repo.getattr(py, "changelog")?.getattr(py, "index")?;
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 Self::create_instance(
py,
RefCell::new(Box::new(CorePartialDiscovery::new(
rust-index: add a function to convert PyObject index for hg-core...
r44398 pyindex_to_graph(py, index)?,
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 rev_pyiter_collect(py, &targetheads)?,
Georges Racinet
rust-discovery: optionally don't randomize at all, for tests...
r42968 respectsize,
randomize,
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 )))
)
}
def addcommons(&self, commons: PyObject) -> PyResult<PyObject> {
let mut inner = self.inner(py).borrow_mut();
let commons_vec: Vec<Revision> = rev_pyiter_collect(py, &commons)?;
inner.add_common_revisions(commons_vec)
.map_err(|e| GraphError::pynew(py, e))?;
Ok(py.None())
}
def addmissings(&self, missings: PyObject) -> PyResult<PyObject> {
let mut inner = self.inner(py).borrow_mut();
let missings_vec: Vec<Revision> = rev_pyiter_collect(py, &missings)?;
inner.add_missing_revisions(missings_vec)
.map_err(|e| GraphError::pynew(py, e))?;
Ok(py.None())
}
def addinfo(&self, sample: PyObject) -> PyResult<PyObject> {
let mut missing: Vec<Revision> = Vec::new();
let mut common: Vec<Revision> = Vec::new();
for info in sample.iter(py)? { // info is a pair (Revision, bool)
let mut revknown = info?.iter(py)?;
let rev: Revision = revknown.next().unwrap()?.extract(py)?;
let known: bool = revknown.next().unwrap()?.extract(py)?;
if known {
common.push(rev);
} else {
missing.push(rev);
}
}
let mut inner = self.inner(py).borrow_mut();
inner.add_common_revisions(common)
.map_err(|e| GraphError::pynew(py, e))?;
inner.add_missing_revisions(missing)
.map_err(|e| GraphError::pynew(py, e))?;
Ok(py.None())
}
def hasinfo(&self) -> PyResult<bool> {
Ok(self.inner(py).borrow().has_info())
}
def iscomplete(&self) -> PyResult<bool> {
Ok(self.inner(py).borrow().is_complete())
}
Georges Racinet
rust-discovery: implementing and exposing stats()...
r42357 def stats(&self) -> PyResult<PyDict> {
let stats = self.inner(py).borrow().stats();
let as_dict: PyDict = PyDict::new(py);
as_dict.set_item(py, "undecided",
Georges Racinet
rust-python3: compatibility fix for integer conversion...
r42519 stats.undecided.map(
|l| l.to_py_object(py).into_object())
.unwrap_or_else(|| py.None()))?;
Georges Racinet
rust-discovery: implementing and exposing stats()...
r42357 Ok(as_dict)
}
Georges Racinet
rust-cpython: removed now useless py_set() conversion...
r43563 def commonheads(&self) -> PyResult<HashSet<Revision>> {
self.inner(py).borrow().common_heads()
.map_err(|e| GraphError::pynew(py, e))
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 }
Georges Racinet
rust-discovery: exposing sampling to python...
r42967
def takefullsample(&self, _headrevs: PyObject,
size: usize) -> PyResult<PyObject> {
let mut inner = self.inner(py).borrow_mut();
let sample = inner.take_full_sample(size)
.map_err(|e| GraphError::pynew(py, e))?;
let as_vec: Vec<PyObject> = sample
.iter()
.map(|rev| rev.to_py_object(py).into_object())
.collect();
Ok(PyTuple::new(py, as_vec.as_slice()).into_object())
}
def takequicksample(&self, headrevs: PyObject,
size: usize) -> PyResult<PyObject> {
let mut inner = self.inner(py).borrow_mut();
let revsvec: Vec<Revision> = rev_pyiter_collect(py, &headrevs)?;
let sample = inner.take_quick_sample(revsvec, size)
.map_err(|e| GraphError::pynew(py, e))?;
let as_vec: Vec<PyObject> = sample
.iter()
.map(|rev| rev.to_py_object(py).into_object())
.collect();
Ok(PyTuple::new(py, as_vec.as_slice()).into_object())
}
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 });
/// Create the module, with __package__ given from parent
pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
let dotted_name = &format!("{}.discovery", package);
let m = PyModule::new(py, dotted_name)?;
m.add(py, "__package__", package)?;
m.add(
py,
"__doc__",
"Discovery of common node sets - Rust implementation",
)?;
m.add_class::<PartialDiscovery>(py)?;
let sys = PyModule::import(py, "sys")?;
let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?;
sys_modules.set_item(py, dotted_name, &m)?;
// Example C code (see pyexpat.c and import.c) will "give away the
// reference", but we won't because it will be consumed once the
// Rust PyObject is dropped.
Ok(m)
}