[Updated] D11721: rhg: more efficient `HgPath::join`

aalekseyev (Arseniy Alekseyev) phabricator at mercurial-scm.org
Wed Oct 27 11:54:10 UTC 2021


aalekseyev added a comment.


  The command `hg debugignorerhg` I introduced in https://phab.mercurial-scm.org/D11722 on a repo with a ~3k line hgignore takes ~31ms after this patch and ~32.5 before this patch.
  
  I looked at the benefit of pre-allocating the HgPathBuf of the right size from the start, but I couldn't measure much improvement, if any. (possibly because I don't have a sensitive benchmark)
  The patch looks like this:
  
    diff --git a/rust/hg-core/src/utils/hg_path.rs b/rust/hg-core/src/utils/hg_path.rs
    --- a/rust/hg-core/src/utils/hg_path.rs
    +++ b/rust/hg-core/src/utils/hg_path.rs
    @@ -172,6 +172,13 @@ impl HgPath {
                 inner: self.inner.to_owned(),
             }
         }
    +    fn to_hg_path_buf_with_spare_capacity(&self, spare_capacity : usize) -> HgPathBuf {
    +        let mut vec = Vec::with_capacity(self.len() + spare_capacity);
    +        vec.extend(&self.inner);
    +        HgPathBuf {
    +            inner: vec,
    +        }
    +    }
         pub fn bytes(&self) -> std::slice::Iter<u8> {
             self.inner.iter()
         }
    @@ -222,7 +229,7 @@ impl HgPath {
         }
     
         pub fn join(&self, path: &HgPath) -> HgPathBuf {
    -        let mut buf = self.to_owned();
    +        let mut buf = self.to_hg_path_buf_with_spare_capacity(path.len() + 1);
             buf.push(path);
             buf
         }
  
  I'm happy to push that if you think that's better.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11721/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D11721

To: aalekseyev, #hg-reviewers, Alphare
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20211027/43654757/attachment-0002.html>


More information about the Mercurial-patches mailing list