Skip to content

Commit

Permalink
Use larger sample sizes for known requests when possible
Browse files Browse the repository at this point in the history
httppostargs allow larger requests, and so does ssh/local.
  • Loading branch information
glandium committed Jun 14, 2024
1 parent 2a23d8e commit 9df2dac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/hg_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ pub trait HgConnectionBase {
);
}
}

fn sample_size(&self) -> usize {
100
}
}

pub trait HgWireConnection: HgConnectionBase {
Expand Down Expand Up @@ -317,6 +321,10 @@ impl<C: HgWireConnection> HgConnectionBase for HgWired<C> {
fn get_capability(&self, name: &[u8]) -> Option<&BStr> {
self.conn.get_capability(name)
}

fn sample_size(&self) -> usize {
self.conn.sample_size()
}
}

impl<C: HgWireConnection> HgConnection for HgWired<C> {
Expand Down Expand Up @@ -633,8 +641,6 @@ fn take_sample<R: rand::Rng + ?Sized, T>(rng: &mut R, data: &mut Vec<T>, size: u
}
}

pub const SAMPLE_SIZE: usize = 100;

#[derive(Default, Debug)]
struct FindCommonInfo {
hg_node: Option<HgChangesetId>,
Expand All @@ -652,7 +658,8 @@ pub fn find_common(
if undetermined.is_empty() {
return vec![];
}
let sample = take_sample(&mut rng, &mut undetermined, SAMPLE_SIZE);
let sample_size = conn.sample_size();
let sample = take_sample(&mut rng, &mut undetermined, sample_size);

let (known, unknown): (Vec<_>, Vec<_>) =
conn.known(&sample)
Expand Down Expand Up @@ -731,12 +738,12 @@ pub fn find_common(
}

while undetermined_count > 0 {
if undetermined.len() < SAMPLE_SIZE {
if undetermined.len() < sample_size {
undetermined.extend(
// TODO: this would or maybe would not be faster if traversing the dag instead.
dag.iter_mut()
.filter(|(_, data)| data.known.is_none())
.choose_multiple(&mut rng, SAMPLE_SIZE - undetermined.len())
.choose_multiple(&mut rng, sample_size - undetermined.len())
.into_iter()
.map(|(&c, data)| {
let git_cs = GitChangesetId::from_unchecked(c);
Expand All @@ -750,7 +757,7 @@ pub fn find_common(
);
}
let (sample_hg, sample_git): (Vec<_>, Vec<_>) =
take_sample(&mut rng, &mut undetermined, SAMPLE_SIZE)
take_sample(&mut rng, &mut undetermined, sample_size)
.into_iter()
.unzip();
for (&known, &c) in conn.known(&sample_hg).iter().zip(sample_git.iter()) {
Expand Down
8 changes: 8 additions & 0 deletions src/hg_connect_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,14 @@ impl HgConnectionBase for HgHttpConnection {
fn get_capability(&self, name: &[u8]) -> Option<&BStr> {
self.capabilities.get_capability(name)
}

fn sample_size(&self) -> usize {
if self.capabilities.get_capability(b"httppostargs").is_some() {
10000
} else {
100
}
}
}

impl Drop for HgHttpConnection {
Expand Down
4 changes: 4 additions & 0 deletions src/hg_connect_stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ impl HgConnectionBase for HgStdioConnection {
fn get_capability(&self, name: &[u8]) -> Option<&BStr> {
self.capabilities.get_capability(name)
}

fn sample_size(&self) -> usize {
10000
}
}

impl Drop for HgStdioConnection {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ fn do_fetch(store: &mut Store, remote: &OsStr, revs: &[OsString]) -> Result<(),
let unknown = revs
.iter()
.filter_map(|r| r.left())
.chunks(hg_connect::SAMPLE_SIZE)
.chunks(conn.sample_size())
.into_iter()
.find_map(|chunk| {
let chunk = chunk.collect_vec();
Expand Down Expand Up @@ -1065,7 +1065,7 @@ fn do_reclone(store: &mut Store, rebase: bool) -> Result<(), String> {
let mut conn = get_connection(&url).unwrap();

let knowns = unknowns
.chunks(hg_connect::SAMPLE_SIZE)
.chunks(conn.sample_size())
.map(|unknowns| {
conn.known(&unknowns.iter().map(|(_, csid)| *csid).collect_vec())
.into_vec()
Expand Down

0 comments on commit 9df2dac

Please sign in to comment.