Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-cpython/src/revlog.rs @ 52009:609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
This does not add too much complexity to the native code and help with
branchmap v3 performance.
Note that the final conversion of the heads from native-code to Python is still
too costly, especially in Rust. In addition the current caching around headrevs
is too simple and fragile. However these are an unrelated problem.
### benchmark.name = hg.command.unbundle
# bin-env-vars.hg.py-re2-module = default
# benchmark.variants.issue6528 = disabled
# benchmark.variants.resource-usage = default
# benchmark.variants.reuse-external-delta-parent = yes
# benchmark.variants.revs = any-1-extra-rev
# benchmark.variants.source = unbundle
# benchmark.variants.validate = default
# benchmark.variants.verbosity = quiet
## data-env-vars.name = netbeans-2018-08-01-zstd-sparse-revlog
# bin-env-vars.hg.flavor = default
branch-v2: 0.233711 ~~~~~
branch-v3 before: 0.239857 (+2.63%, +0.01)
branch-v3 after: 0.239558 (+2.50%, +0.01)
# bin-env-vars.hg.flavor = rust
branch-v2: 0.235230 ~~~~~
branch-v3 before: 0.240972 (+2.44%, +0.01)
branch-v3 after: 0.239917 (+1.99%, +0.00)
## data-env-vars.name = netbeans-2018-08-01-ds2-pnm
# bin-env-vars.hg.flavor = rust
branch-v2: 0.255586 ~~~~~
branch-v3 before: 0.268560 (+5.08%, +0.01)
branch-v3 after: 0.262261 (+2.61%, +0.01)
## data-env-vars.name = mozilla-central-2024-03-22-zstd-sparse-revlog
# bin-env-vars.hg.flavor = default
branch-v2: 0.339010 ~~~~~
branch-v3 before: 0.349389 (+3.06%, +0.01)
branch-v3 after: 0.348247 (+2.72%, +0.01)
# bin-env-vars.hg.flavor = rust
branch-v2: 0.346525 ~~~~~
branch-v3 before: 0.355661 (+2.64%, +0.01)
branch-v3 after: 0.350906 (+1.26%, +0.00)
## data-env-vars.name = mozilla-central-2024-03-22-ds2-pnm
# bin-env-vars.hg.flavor = rust
branch-v2: 0.380202 ~~~~~
branch-v3 before: 0.408851 (+7.54%, +0.03)
branch-v3 after: 0.406511 (+6.92%, +0.03)
## data-env-vars.name = mozilla-unified-2024-03-22-zstd-sparse-revlog
# bin-env-vars.hg.flavor = default
branch-v2: 0.412165 ~~~~~
branch-v3 before: 0.427782 (+3.79%, +0.02)
branch-v3 after: 0.422595 (+2.53%, +0.01)
# bin-env-vars.hg.flavor = rust
branch-v2: 0.412397 ~~~~~
branch-v3 before: 0.422354 (+2.41%, +0.01)
branch-v3 after: 0.421079 (+2.11%, +0.01)
## data-env-vars.name = mozilla-unified-2024-03-22-ds2-pnm
# bin-env-vars.hg.flavor = rust
branch-v2: 0.429501 ~~~~~
branch-v3 before: 0.443197 (+3.19%, +0.01)
branch-v3 after: 0.449432 (+4.64%, +0.02)
## data-env-vars.name = mozilla-try-2024-03-26-zstd-sparse-revlog
# bin-env-vars.hg.flavor = default
branch-v2: 3.403171 ~~~~~
branch-v3 before: 3.819477 (+12.23%, +0.42)
branch-v3 after: 3.658482 (+7.50%, +0.26)
# bin-env-vars.hg.flavor = rust
branch-v2: 3.454876 ~~~~~
branch-v3 before: 3.590284 (+3.92%, +0.14)
branch-v3 after: 3.545843 (+2.63%, +0.09)
## data-env-vars.name = mozilla-try-2024-03-26-ds2-pnm
# bin-env-vars.hg.flavor = rust
branch-v2: 3.465435 ~~~~~
branch-v3 before: 3.633278 (+4.84%, +0.17)
branch-v3 after: 3.556074 (+2.62%, +0.09)
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 27 Sep 2024 03:55:40 +0200 |
parents | 69bfd6b242ed |
children | 3e135e79b7f7 |
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs Thu Sep 26 01:52:09 2024 +0200 +++ b/rust/hg-cpython/src/revlog.rs Fri Sep 27 03:55:40 2024 +0200 @@ -27,7 +27,10 @@ revlog::{nodemap::NodeMap, Graph, NodePrefix, RevlogError, RevlogIndex}, BaseRevision, Node, Revision, UncheckedRevision, NULL_REVISION, }; -use std::{cell::RefCell, collections::HashMap}; +use std::{ + cell::RefCell, + collections::{HashMap, HashSet}, +}; use vcsgraph::graph::Graph as VCSGraph; pub struct PySharedIndex { @@ -305,12 +308,13 @@ /// get head revisions def headrevs(&self, *args, **_kw) -> PyResult<PyObject> { - let filtered_revs = match &args.len(py) { - 0 => Ok(py.None()), - 1 => Ok(args.get_item(py, 0)), + let (filtered_revs, stop_rev) = match &args.len(py) { + 0 => Ok((py.None(), py.None())), + 1 => Ok((args.get_item(py, 0), py.None())), + 2 => Ok((args.get_item(py, 0), args.get_item(py, 1))), _ => Err(PyErr::new::<cpython::exc::TypeError, _>(py, "too many arguments")), }?; - self.inner_headrevs(py, &filtered_revs) + self.inner_headrevs(py, &filtered_revs, &stop_rev) } /// get head nodeids @@ -821,29 +825,62 @@ &self, py: Python, filtered_revs: &PyObject, + stop_rev: &PyObject, ) -> PyResult<PyObject> { let index = &*self.index(py).borrow(); - - let from_core = match filtered_revs.is_none(py) { - true => index.head_revs_shortcut(), + let stop_rev = match stop_rev.is_none(py) { false => { + let rev = stop_rev.extract::<i32>(py)?; + if 0 <= rev && rev < index.len() as BaseRevision { + Some(Revision(rev)) + } else { + None + } + } + true => None, + }; + let from_core = match (filtered_revs.is_none(py), stop_rev.is_none()) { + (true, true) => index.head_revs_shortcut(), + (true, false) => { + index.head_revs_advanced(&HashSet::new(), stop_rev, false) + } + _ => { let filtered_revs = rev_pyiter_collect(py, filtered_revs, index)?; - index.head_revs_filtered(&filtered_revs, true) + index.head_revs_advanced( + &filtered_revs, + stop_rev, + stop_rev.is_none(), + ) } }; - if let Some(new_heads) = from_core.map_err(|e| graph_error(py, e))? { - self.cache_new_heads_py_list(&new_heads, py); - } + if stop_rev.is_some() { + // we don't cache result for now + let new_heads = from_core + .map_err(|e| graph_error(py, e))? + .expect("this case should not be cached yet"); - Ok(self - .head_revs_py_list(py) - .borrow() - .as_ref() - .expect("head revs should be cached") - .clone_ref(py) - .into_object()) + let as_vec: Vec<PyObject> = new_heads + .iter() + .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) + .collect(); + Ok(PyList::new(py, &as_vec).into_object()) + } else { + if let Some(new_heads) = + from_core.map_err(|e| graph_error(py, e))? + { + self.cache_new_heads_py_list(&new_heads, py); + } + + Ok(self + .head_revs_py_list(py) + .borrow() + .as_ref() + .expect("head revs should be cached") + .clone_ref(py) + .into_object()) + } } fn check_revision(