Skip to content

perf(watcher): catch-up SHA-256 fingerprints every file, making restart O(n) in I/O #736

Closed

Description

@Sinity

Problem

During catch-up, _ingest_if_grown() calls _fingerprint_file() which reads the ENTIRE file into memory and SHA-256 hashes it — just to check if it changed. For 10,000 files at 14MB average, this is 140GB of I/O before any parsing work occurs.

At measured speeds (11 records in 205s), catch-up of 10,000 files would take ~52 hours linearly. Even with parallelism (8 workers), the bottleneck is SQLite writes (single-threaded) and SHA-256 I/O (sequential per file).

The cursor already stores file_mtime_ns — if mtime hasn't changed since the cursor was written, the file almost certainly hasn't changed. A stat()-only fast path could skip the full read+hash for unchanged files.

Acceptance criteria

  • Add mtime-based fast path: if cursor has file_mtime_ns and it matches current st_mtime_ns AND st_size matches byte_size, skip the full SHA-256 read.
  • Fall back to full fingerprint on any mismatch (safe — false negative just re-reads unnecessarily).
  • Benchmark catch-up time before and after on a realistic file tree.

Found by

2026-05-03 red team performance review (wave 6). Related to #620 (live cursor).

Activity

  1. Sinity commented on May 3, 2026

    @Sinity
    OwnerAuthor

    Cursor schema needs to be richer than fingerprint+offset

    The mtime fast-path AC assumes cursor metadata already supports it, but the live implementation still centers on whole-file fingerprinting. Each watched-file cursor row should carry:

    • st_dev, st_ino (rename/move detection)
    • st_size, mtime_ns (fast-path skip)
    • byte_offset, last_complete_newline (resumable append parsing)
    • content_fingerprint, parser_fingerprint (correctness re-check)
    • source_generation (forced rescans bump this)
    • failure_count, next_retry_at, excluded (poison-pill quarantine, surfaced via status)

    This schema simultaneously addresses #736, #733, #739, #740, and part of #719.

    Anti-regression breaker

    Add a no-op catch-up test that fails if Path.read_bytes() (or any full-file read) is called when (st_dev, st_ino, st_size, mtime_ns) matches the cursor. Without this, the fast path silently regresses on the next refactor and the 140 GB problem comes back.

  2. Sinity commented on May 3, 2026

    @Sinity
    OwnerAuthor

    Closed by #758. Cursor schema expanded with st_dev/st_ino/st_size/mtime_ns/byte_offset/failure_count/excluded. Stat-based fast path skips full reads. 7 breaker tests in test_acquisition_fast_path.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions