From d7c5d438ca9afbfdbbb985eee98f5936d6c252f8 Mon Sep 17 00:00:00 2001 From: Bradley Hilton Date: Tue, 22 Sep 2026 08:49:11 -0500 Subject: [PATCH] test: skip redb per-commit fsync in the shared test repo helper Windows CI spends roughly 15 minutes running tests that take 6 on Linux. The spread is concentrated in filesystem-heavy suites (atomic_repository 15x, atomic_teams 4x, database_owner 6x), consistent with redb's default per-commit fsync being the dominant cost on NTFS. Add a durability knob on Pristine (set_durability, applied in write_txn) and Repository::init_with_view_durability, then have the shared test helper create_temp_repo open repositories with redb Durability::None. Commits stay visible to later handles through the OS page cache, so reopen-style tests remain correct; only crash durability is traded, which tests never exercise. Production paths keep Durability::Immediate. Local macOS before/after for the atomic-repository lib suite: 85.9s to 76.8s (about 11%). The NTFS fsync cost is much larger than APFS, so the Windows gain is expected to be substantially bigger. --- atomic-core/src/pristine/txn/pristine.rs | 15 +++++++++++- atomic-repository/src/repository/mod.rs | 23 +++++++++++++++---- atomic-repository/src/repository/tests/mod.rs | 9 +++++++- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/atomic-core/src/pristine/txn/pristine.rs b/atomic-core/src/pristine/txn/pristine.rs index 566ef487..9981f81f 100644 --- a/atomic-core/src/pristine/txn/pristine.rs +++ b/atomic-core/src/pristine/txn/pristine.rs @@ -91,6 +91,9 @@ fn open_database(path: &Path, create: bool, cache_bytes: usize) -> PristineResul /// ``` pub struct Pristine { db: PristineDatabase, + /// Redb commit durability. Tests lower this to skip fsync per commit, + /// which dominates the runtime of filesystem-heavy suites on Windows. + durability: redb::Durability, /// Counter for allocating node IDs pub(crate) next_node_id: AtomicU64, /// Counter for allocating view IDs @@ -222,6 +225,7 @@ impl Pristine { Ok(Self { db: PristineDatabase::Writable(db), + durability: redb::Durability::Immediate, next_node_id, next_view_id, next_inode, @@ -328,12 +332,19 @@ impl Pristine { Ok(Self { db, + durability: redb::Durability::Immediate, next_node_id, next_view_id, next_inode, }) } + /// Override the redb commit durability for this handle. Tests use this + /// to skip per-commit fsync; production keeps the durable default. + pub fn set_durability(&mut self, durability: redb::Durability) { + self.durability = durability; + } + /// Begin a read-only transaction /// /// Read transactions can run concurrently with other read transactions @@ -355,7 +366,9 @@ impl Pristine { "cannot write through a read-only pristine handle", ))); }; - let txn = db.begin_write()?; + let mut txn = db.begin_write()?; + txn.set_durability(self.durability) + .map_err(|e| PristineError::Io(std::io::Error::other(e.to_string())))?; Ok(WriteTxn::new( txn, &self.next_node_id, diff --git a/atomic-repository/src/repository/mod.rs b/atomic-repository/src/repository/mod.rs index 4c98e8fe..2ddd65b6 100644 --- a/atomic-repository/src/repository/mod.rs +++ b/atomic-repository/src/repository/mod.rs @@ -274,6 +274,19 @@ impl Repository { pub fn init_with_view>( path: P, view_name: &str, + ) -> Result { + Self::init_with_view_durability(path, view_name, redb::Durability::Immediate) + } + + /// Like [`Self::init_with_view`], with an explicit redb commit durability. + /// + /// Tests pass [`redb::Durability::None`] to skip per-commit fsync, which + /// dominates the runtime of filesystem-heavy repository suites (notably + /// on Windows). Production callers keep the durable default. + pub fn init_with_view_durability>( + path: P, + view_name: &str, + durability: redb::Durability, ) -> Result { let root = path.as_ref().to_path_buf(); let dot_dir = root.join(DOT_DIR); @@ -307,10 +320,12 @@ default = "{}" std::fs::write(&wc_id_path, "")?; // Initialize the pristine database (redb creates the file) - let pristine = Arc::new( - Pristine::open(dot_dir.join("pristine.redb")) - .map_err(|e| RepositoryError::Database(e.to_string()))?, - ); + let pristine = { + let mut pristine = Pristine::open(dot_dir.join("pristine.redb")) + .map_err(|e| RepositoryError::Database(e.to_string()))?; + pristine.set_durability(durability); + Arc::new(pristine) + }; // Create the default view and its workspace directory { diff --git a/atomic-repository/src/repository/tests/mod.rs b/atomic-repository/src/repository/tests/mod.rs index 3ef5342a..07c0dce6 100644 --- a/atomic-repository/src/repository/tests/mod.rs +++ b/atomic-repository/src/repository/tests/mod.rs @@ -28,7 +28,14 @@ mod view_tests; pub(super) fn create_temp_repo() -> (TempDir, Repository) { let temp_dir = TempDir::new().unwrap(); - let repo = Repository::init(temp_dir.path()).unwrap(); + // Durability::None skips per-commit fsync, which dominates these + // filesystem-heavy tests (especially on Windows). Redb still makes + // commits visible to later handles through the OS page cache, so + // reopen-style tests remain correct; only crash-durability is lost, + // which tests never need. + let repo = + Repository::init_with_view_durability(temp_dir.path(), "dev", redb::Durability::None) + .unwrap(); (temp_dir, repo) }