diff rust/hg-cpython/src/revlog.rs @ 51226:1b23aaf5eb7b

rust-index: optimize find_gca_candidates() on less than 8 revisions This is expected to be by far the most common case, given that, e.g., merging involves using it on two revisions. Using a `u8` as support for the bitset obviously divides the amount of RAM needed by 8. To state the obvious, on a repository with 10 million changesets, this spares 70MB. It is also possible that it'd be slightly faster, because it is easier to allocate and provides better cache locality. It is possible that some exhaustive listing of the traits implemented by `u8` and `u64` would avoid the added duplication, but that can be done later and would need a replacement for the `MAX` consts.
author Georges Racinet <georges.racinet@octobus.net>
date Fri, 20 Oct 2023 09:12:22 +0200
parents 89ce6a49bfeb
children 5807e3a8865e
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs	Fri Oct 20 08:54:49 2023 +0200
+++ b/rust/hg-cpython/src/revlog.rs	Fri Oct 20 09:12:22 2023 +0200
@@ -20,7 +20,10 @@
 };
 use hg::{
     errors::HgError,
-    index::{IndexHeader, Phase, RevisionDataParams, SnapshotsCache},
+    index::{
+        IndexHeader, Phase, RevisionDataParams, SnapshotsCache,
+        INDEX_ENTRY_SIZE,
+    },
     nodemap::{Block, NodeMapError, NodeTree},
     revlog::{nodemap::NodeMap, NodePrefix, RevlogError, RevlogIndex},
     BaseRevision, Revision, UncheckedRevision, NULL_REVISION,
@@ -483,12 +486,26 @@
 
     @property
     def entry_size(&self) -> PyResult<PyInt> {
-        self.cindex(py).borrow().inner().getattr(py, "entry_size")?.extract::<PyInt>(py)
+        let rust_res: PyInt = INDEX_ENTRY_SIZE.to_py_object(py);
+
+        let c_res = self.cindex(py).borrow().inner()
+            .getattr(py, "entry_size")?;
+        assert_py_eq(py, "entry_size", rust_res.as_object(), &c_res)?;
+
+        Ok(rust_res)
     }
 
     @property
     def rust_ext_compat(&self) -> PyResult<PyInt> {
-        self.cindex(py).borrow().inner().getattr(py, "rust_ext_compat")?.extract::<PyInt>(py)
+        // will be entirely removed when the Rust index yet useful to
+        // implement in Rust to detangle things when removing `self.cindex`
+        let rust_res: PyInt = 1.to_py_object(py);
+
+        let c_res = self.cindex(py).borrow().inner()
+            .getattr(py, "rust_ext_compat")?;
+        assert_py_eq(py, "rust_ext_compat", rust_res.as_object(), &c_res)?;
+
+        Ok(rust_res)
     }
 
 });
@@ -671,7 +688,7 @@
         let rust_index_len = self.index(py).borrow().len();
         let cindex_len = self.cindex(py).borrow().inner().len(py)?;
         assert_eq!(rust_index_len, cindex_len);
-        Ok(cindex_len)
+        Ok(rust_index_len)
     }
 
     /// This is scaffolding at this point, but it could also become