Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Counting index hunks by iteration is slightly inefficient #137

Open
sourcefrog opened this issue Jul 4, 2020 · 0 comments
Open

Counting index hunks by iteration is slightly inefficient #137

sourcefrog opened this issue Jul 4, 2020 · 0 comments

Comments

@sourcefrog
Copy link
Owner

sourcefrog commented Jul 4, 2020

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
Projects
None yet
Development

No branches or pull requests

1 participant