Skip to content

Counting index hunks by iteration is slightly inefficient #137

Open

Description

@sourcefrog

From #133 (comment)

Current code (

conserve/src/index.rs

Lines 237 to 256 in bd6759f

pub fn count_hunks(&self) -> Result<u32> {
// TODO: Might be faster to list the directory than to probe for all of them.
// TODO: Perhaps, list the directories and cope cleanly with
// one hunk being missing.
for i in 0.. {
let path = hunk_relpath(i);
if !self
.transport
.exists(&path)
.map_err(|source| Error::ReadIndex {
source,
path: path.into(),
})?
{
// If hunk 1 is missing, 1 hunks exists.
return Ok(i);
}
}
unreachable!();
}
) to determine the number of index hunks probes for each of them, which is a bit inefficient. However this is only done once per restore, so it's not really a hot path.

Better ways to do this:

  • look in the band tail for a count, if it's there
  • otherwise, list the index directories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions