Skip to content

Commit

Permalink
hgmanifest: don't overallocate when loading manifests
Browse files Browse the repository at this point in the history
Summary: We are using the upperbound of `<[u8]>::split`'s iterator as the value for `with_capacity`, however this is incredibly pessimistic, and as a result we overallocate.  Let's just make an initial pass and count the actual number.

Reviewed By: RajivTS

Differential Revision: D49951367

fbshipit-source-id: c3ce6fa0d4125f2cac26c9ea017a0992f9291397
  • Loading branch information
markbt authored and facebook-github-bot committed Oct 5, 2023
1 parent 0db20e2 commit eb74959
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions eden/mononoke/mercurial/types/src/blobs/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ impl ManifestContent {
data: &[u8],
) -> Result<SortedVectorMap<MPathElement, Entry<HgManifestId, (FileType, HgFileNodeId)>>> {
let lines = data.split(|b| *b == b'\n');
let mut files = match lines.size_hint() {
// Split returns it count in the high size hint
(_, Some(high)) => SortedVectorMap::with_capacity(high),
(_, None) => SortedVectorMap::new(),
};
let count = lines.clone().count();
let mut files = SortedVectorMap::with_capacity(count);

for line in lines {
if line.is_empty() {
Expand Down

0 comments on commit eb74959

Please sign in to comment.