annotate rust/hg-core/src/fncache.rs @ 52316:f4aede0f01af

rust-manifest: use `memchr` crate for all byte-finding needs While writing a very dumb manifest diffing algorithm for a proof-of-concept I saw that `Manifest::find_by_path` was much slower than I was expecting. It turns out that the Rust stdlib uses slow (all is relative) code when searching for byte positions for reasons ranging from portability, SIMD API stability, nobody doing the work, etc. `memch` is much faster for these purposes, so let's use it. I was measuring ~670ms of profile time in `find_by_path`, after this patch it went down to ~230ms.
author Rapha?l Gom?s <rgomes@octobus.net>
date Tue, 12 Nov 2024 23:20:04 +0100
parents 1a8466fd904a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52296
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
1 use std::path::Path;
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
2
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
3 use dyn_clone::DynClone;
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
4
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
5 /// The FnCache stores the list of most files contained in the store and is
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
6 /// used for stream/copy clones.
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
7 ///
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
8 /// It keeps track of the name of "all" indexes and data files for all revlogs.
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
9 /// The names are relative to the store roots and are stored before any
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
10 /// encoding or path compression.
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
11 ///
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
12 /// Despite its name, the FnCache is *NOT* a cache, it keep tracks of
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
13 /// information that is not easily available elsewhere. It has no mechanism
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
14 /// for detecting isn't up to date, and de-synchronization with the actual
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
15 /// contents of the repository will lead to a corrupted clone and possibly
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
16 /// other corruption during maintenance operations.
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
17 /// Strictly speaking, it could be recomputed by looking at the contents of all
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
18 /// manifests AND actual store files on disk, however that is a
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
19 /// prohibitively expensive operation.
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
20 pub trait FnCache: Sync + Send + DynClone {
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
21 /// Whether the fncache was loaded from disk
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
22 fn is_loaded(&self) -> bool;
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
23 /// Add a path to be tracked in the fncache
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
24 fn add(&self, path: &Path);
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
25 // TODO add more methods once we start doing more with the FnCache
1a8466fd904a hg-core: add fncache module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
26 }