Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions apps/origin-src/benches/annotations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Statements: input digests over a large snapshot, and the promotion
//! search over many statements, with their digests cached by the index and
//! without.
//! Benchmarks for statements: the input digest of a large snapshot, and
//! the promotion search over many statements, with and without their
//! digests cached in the index.

use std::fs;

Expand Down Expand Up @@ -42,8 +42,9 @@ fn inputs(paths: &[&str], definition: &str) -> Inputs {
}
}

/// The input digest of the 20k-file fixture, for inputs naming two
/// directories, a file and a missing path. Each run reads the trees anew.
/// Benchmarks the input digest of the 20k-file fixture, for inputs naming
/// two directories, a file and a missing path. Each run reads the trees
/// anew.
#[divan::bench(sample_count = 50)]
fn input_digest(bencher: Bencher<'_, '_>) {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -81,8 +82,9 @@ const CHECKS: [(&str, &[&str]); 10] = [
("ci.unit", &["src"]),
];

/// A snapshot of a small crate, at version `version` of its sources and
/// `docs` of its documentation.
/// Builds the objects of a small crate's snapshot, with version `version`
/// of its sources and version `docs` of its documentation. The root tree
/// comes last.
fn snapshot(version: usize, docs: usize) -> Vec<EncodedObject> {
let file = |content: String| {
let blob = EncodedObject::blob(content.as_bytes());
Expand Down Expand Up @@ -123,9 +125,9 @@ fn snapshot(version: usize, docs: usize) -> Vec<EncodedObject> {
objects
}

/// A store with a revision of its own change for each version, each with a
/// result of every check, 20k statements in all, and a revision whose
/// sources match one of them.
/// Builds a store with one revision per version, each of its own change
/// and with a passing result of every check: 20k statements in all. Returns
/// it with one more revision, whose sources match one of the others.
fn promotion_store() -> (tempfile::TempDir, Store, RevisionId) {
let (dir, store) = store();
let revision = |store: &Store, change: usize, version: usize, docs: usize| {
Expand Down Expand Up @@ -173,8 +175,9 @@ fn promotion_store() -> (tempfile::TempDir, Store, RevisionId) {
(dir, store, target)
}

/// Searching 20k statements for those to promote to a revision, with every
/// digest cached: the cost of each search after the first.
/// Benchmarks searching 20k statements for those to promote to a
/// revision, with every digest already cached: the cost of every search
/// after the first.
#[divan::bench(sample_count = 20)]
fn promotions_cached(bencher: Bencher<'_, '_>) {
let (_dir, store, target) = promotion_store();
Expand All @@ -198,8 +201,8 @@ fn promotions_cached(bencher: Bencher<'_, '_>) {
});
}

/// The first search, which computes and remembers the digest of each of
/// the 20k statements, reading its subject's trees.
/// Benchmarks the first search, which computes the digest of each of the
/// 20k statements from its subject's trees and stores it in the index.
#[divan::bench(sample_count = 10, sample_size = 1)]
fn promotions_uncached(bencher: Bencher<'_, '_>) {
let (dir, store, target) = promotion_store();
Expand Down
46 changes: 23 additions & 23 deletions apps/origin-src/src/ancestry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Merge bases in a history of immutable records with snapshots: the
//! acceptances of targets, each after the one before it and the
//! acceptances it landed, or the revisions of a change, each after its
//! predecessors.
//! Finds merge bases in a history of records that each have parents and a
//! snapshot. The records are either the acceptances of a target, whose
//! parents are the acceptance before and the acceptances it landed, or the
//! revisions of a change, whose parents are their predecessors.

use std::collections::{HashMap, HashSet};
use std::hash::Hash;
Expand All @@ -19,12 +19,12 @@ pub struct Ancestry<I> {
}

impl<I: Copy + Eq + Hash + Ord> Ancestry<I> {
/// Walks everything `tips` descend from, asking `read` for the parents
/// and the snapshot of each record, once.
/// Walks every record `tips` descend from, `tips` included, calling
/// `read` once per record for its parents and snapshot.
///
/// # Errors
///
/// Fails as `read` does.
/// Fails if `read` fails.
pub fn walk<E>(
tips: &[I],
mut read: impl FnMut(I) -> Result<(Vec<I>, TreeId), E>,
Expand All @@ -42,13 +42,13 @@ impl<I: Copy + Eq + Hash + Ord> Ancestry<I> {
Ok(Self { records })
}

/// The snapshot to merge `tips` from, `None` if they share no ancestor:
/// that of their best common ancestor. Several, as histories that
/// merged each other criss-cross have, merge into one first, as git's
/// recursive strategy does: each from their own merge base, with what
/// [`Store::merge_bases`] leaves where they conflict, so a merge from
/// the result conflicts there, and under it, unless both sides agree. Writes the trees
/// that makes, which merging reads.
/// Returns the snapshot to merge `tips` from: that of their best common
/// ancestor, or `None` if they have no common ancestor. When there are
/// several best common ancestors, as after criss-cross merges, it first
/// merges them into one with [`Store::merge_bases`], like git's recursive
/// strategy. A merge from the result then conflicts at or under every path
/// where those ancestors conflicted, unless both sides agree. Writes the
/// trees this makes to the store.
///
/// # Errors
///
Expand All @@ -62,7 +62,8 @@ impl<I: Copy + Eq + Hash + Ord> Ancestry<I> {
self.merge_base_of(store, &groups)
}

/// The snapshot to merge `groups` from, each standing for all it holds.
/// Like [`Self::merge_base`], but for groups of records: each group stands
/// for a merge of all its records.
fn merge_base_of<P: Platform>(
&self,
store: &Store<P>,
Expand All @@ -84,10 +85,9 @@ impl<I: Copy + Eq + Hash + Ord> Ancestry<I> {
Ok(Some(tree))
}

/// The best common ancestors of `groups`: the records that every group
/// has one that is or descends from, but that none of the others
/// descends from, sorted. Each record is visited a bounded number of
/// times.
/// Returns the best common ancestors of `groups`, sorted: the records
/// that are, or are ancestors of, a record in every group, and that no
/// other such record descends from.
fn best_common(&self, groups: &[&[I]]) -> Vec<I> {
let Some((first, others)) = groups.split_first() else {
return Vec::new();
Expand All @@ -104,7 +104,7 @@ impl<I: Copy + Eq + Hash + Ord> Ancestry<I> {
bases
}

/// The records `from` are or descend from.
/// Returns the records in `from` and every record they descend from.
fn reachable(&self, from: impl IntoIterator<Item = I>) -> HashSet<I> {
let mut reached = HashSet::new();
let mut next: Vec<_> = from.into_iter().collect();
Expand All @@ -116,8 +116,8 @@ impl<I: Copy + Eq + Hash + Ord> Ancestry<I> {
reached
}

/// Whether `id` is or descends from `ancestor`, as far as the walk
/// read.
/// Whether `id` is `ancestor` or descends from it, within the records the
/// walk read.
#[must_use]
pub fn descends(&self, id: I, ancestor: I) -> bool {
self.reachable([id]).contains(&ancestor)
Expand All @@ -138,7 +138,7 @@ mod tests {

use super::*;

/// The history of `edges`, each a record and its parents.
/// Builds the history of `edges`, each a record and its parents.
fn ancestry(edges: &[(u8, &[u8])]) -> Ancestry<u8> {
let tips: Vec<_> = edges.iter().map(|&(id, _)| id).collect();
let empty = Tree::default().encode().id().into();
Expand Down
Loading
Loading