Quickstart
ZipXP needs Windows 11 and a local NTFS drive. Install the latest release for your user from Windows PowerShell. It needs no administrator rights:
-PS> curl.exe -fsSL https://kiranscript.github.io/zipxp/install.ps1 -o "$env:TEMP\zipxp-get.ps1" +PS> curl.exe -fsSL https://github.com/kiranscript/zipxp/releases/latest/download/zipxp-get.ps1 -o "$env:TEMP\zipxp-get.ps1" PS> powershell -NoProfile -ExecutionPolicy Bypass -File "$env:TEMP\zipxp-get.ps1"-The script downloads the release ZIP, verifies its SHA-256, runs the per-user installer and cleans up. Add
+-StartAtLogin,-Launchor-Version 0.2.0after-File …if you want them. The checksum catches a damaged download. The release also carries a GitHub build attestation, which the script verifies if the GitHub CLI is installed and signed in (-RequireAttestationmakes that mandatory). The build is not code-signed. Until the first release is published, or if you'd rather build it yourself, use the .NET 10 SDK:The script downloads the release ZIP, verifies its SHA-256, runs the per-user installer and cleans up. Add
-StartAtLogin,-Launchor-Version 0.3.0after-File …if you want them. The checksum catches a damaged download. The release also carries a GitHub build attestation, which the script verifies if the GitHub CLI is installed and signed in (-RequireAttestationmakes that mandatory). The build is not code-signed. Until the first release is published, or if you'd rather build it yourself, use the .NET 10 SDK:PS> git clone https://github.com/kiranscript/zipxp.git PS> cd zipxp PS> dotnet run --project src/ZipXP.App/ZipXP.App.csproj@@ -162,7 +162,7 @@State & recovery
State lives in
%LOCALAPPDATA%\ZipXP\StorageManager\storage.sqlite3, plus its SQLite WAL/SHM files. SQLite is supplied by Windows' ownwinsqlite3.dll. There are no external NuGet or UI packages.After a crash, jobs that were running become retry records, and each file's actual state and identity are checked again. Files changed while ZipXP was closed are found on startup. To back up, exit the tray worker normally and copy the state directory. Newer schema versions are rejected by older builds.
Known issues
-After a restore, the app can measure a file's allocation before its handle is closed. That overstates growth for some file sizes and can show a small negative savings total. The files themselves aren't affected. Tracked in #2. A fix (#4) is merged on a branch but hasn't reached
+mainyet.None open. Before 0.3.0, savings after a restore could be measured while the file was still open, which overstated growth for some file sizes (#2). 0.3.0 measures after the file is closed.
More space.
Same files.
ZipXP shrinks the files in the folders you pick, in place, using Windows' built-in NTFS compression. @@ -440,7 +440,7 @@
Build it, run it, ship it.
# Install the latest release for this user (no admin) -PS> curl.exe -fsSL https://kiranscript.github.io/zipxp/install.ps1 -o "$env:TEMP\zipxp-get.ps1" +PS> curl.exe -fsSL https://github.com/kiranscript/zipxp/releases/latest/download/zipxp-get.ps1 -o "$env:TEMP\zipxp-get.ps1" PS> powershell -NoProfile -ExecutionPolicy Bypass -File "$env:TEMP\zipxp-get.ps1" # Optional: start at sign-in and launch now @@ -530,7 +530,7 @@The fine print, up front.
Is it ready for production use?
-+Not yet. ZipXP 0.2 is an unsigned pre-release. The development checks pass, but broader hardware and antivirus compatibility testing, a release signing certificate, and a real user pilot are still to come. Use disposable copies of your data until then. See boundaries.
Not yet. ZipXP 0.3 is an unsigned pre-release. The development checks pass, but broader hardware and antivirus compatibility testing, a release signing certificate, and a real user pilot are still to come. Use disposable copies of your data until then. See boundaries.
Is there an installer to download?
From ab90e1516035e1d3be0cc7928f11f20f09c1ace1 Mon Sep 17 00:00:00 2001 From: kirank55Date: Thu, 19 Nov 2026 12:01:06 +0000 Subject: [PATCH 2/4] Cut background scanning and per-file overhead on large folders On a 50,000-file test folder the worker loaded and parsed every observation for each file it compressed, and every 2-minute rescan re-sampled every candidate (~1 GB read) and rewrote the whole observations table (~92 MB), even with auto-compression off. - Store.Observed looks up the latest scan's file by identity through an in-memory index rebuilt on each scan, instead of loading every row. - Rescans reuse the stored sampling estimate while a file's identity, length and last-write time are unchanged. - SaveScan writes only added, changed and removed observations. - The safety rescan runs every 30 minutes; watcher events still trigger scans within seconds. Folders without a watcher keep 2 minutes. Results on the same folder: rescan 70 MB read and nothing written instead of ~1 GB and 92 MB; a 3-minute auto-compression run used 12 s CPU instead of 70 s and did 109 files/min instead of 69. Adds checks for estimate reuse and for renames and deletions surviving the diffed writes. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + docs/validation.md | 13 ++++++ src/ZipXP.Core/Persistence/Store.cs | 64 ++++++++++++++++++++++------- src/ZipXP.Core/Services/Analyzer.cs | 10 +++-- src/ZipXP.Core/Services/Engine.cs | 9 ++-- tests/ZipXP.Checks/Program.cs | 18 ++++++++ website/index.html | 2 +- 7 files changed, 96 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6df1761..c861109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to ZipXP are recorded here. The format follows [Keep a Chang ### Fixed - Allocation is now measured after the mutation handle is closed, so savings after a restore are no longer overstated for file sizes that are not cluster-aligned ([#2](https://github.com/kiranscript/zipxp/issues/2)). - The documented install command pointed at a website that is no longer deployed; it now downloads `zipxp-get.ps1` from the latest release. +- Background work on large folders. On a 50,000-file test folder, the worker no longer loads every observation for each file it compresses (CPU during a run fell from 70 s to 12 s per 3 minutes, and throughput rose from 69 to 109 files/min). Rescans reuse sampling estimates for unchanged files and write only changed records (a rescan now reads 70 MB instead of about 1 GB and writes nothing instead of 92 MB). The safety rescan runs every 30 minutes instead of every 2, because file-system notifications already trigger a scan within seconds; it stays at 2 minutes for a folder whose watcher can't start. ### Changed - Repository reorganised into `src/`, `tests/`, `scripts/` and `docs/`; projects renamed from `StorageManager.*` to `ZipXP.*`. diff --git a/docs/validation.md b/docs/validation.md index 52d5c12..82c1902 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -34,6 +34,19 @@ That run found an **allocation-accounting defect** not covered by the earlier al **Fixed (2026-11-19).** The mutator now closes the mutation handle and measures on a fresh handle, and claims no saving if the file changed in between. The core suite reproduced the defect first (65,537 bytes failed), then passed 80 checks, including compress-and-restore round trips at 65,537, 100,003 and 262,147 bytes that net to exactly zero and return to the original allocation. +## Large-folder load test (2026-11-19) + +The real engine ran against a generated 50,000-file folder (10,000 compressible text files of 100–160 KB, 40,000 of 1–8 KB, 1.4 GB) on a local NTFS SSD, with the battery and CPU gates off so they didn't hold work back. The test data was deleted afterwards. + +| | Before | After | +|---|---|---| +| Rescan of an unchanged folder | 10 s CPU, ~1 GB read, 92 MB written | 5 s CPU, 70 MB read, nothing written | +| Rescan interval with a working watcher | 2 minutes | 30 minutes | +| Auto-compression, 3 minutes | 69 files/min, 70 s CPU, 10.3 GB read | 109 files/min, 12 s CPU, 359 MB read | +| Longest wait for a UI command during that run | 8.2 s (during a rescan) | 23 ms (no rescan fell in the window) | + +Scans still hold the engine lock, so a UI command can wait for a rescan to finish (about 5 s on this folder). The window's 3-second refresh still loads every observation (about 0.25 s CPU each time on this folder). Throughput is limited by the 500 ms pause between files by design. + ## Release acceptance still required - Broad Windows/NTFS cluster-size, hardware, permissions, antivirus, and backup/restore compatibility matrix. diff --git a/src/ZipXP.Core/Persistence/Store.cs b/src/ZipXP.Core/Persistence/Store.cs index 3077b1d..5213250 100644 --- a/src/ZipXP.Core/Persistence/Store.cs +++ b/src/ZipXP.Core/Persistence/Store.cs @@ -7,6 +7,8 @@ public sealed class Store : IDisposable private readonly Sqlite db; public string DatabasePath { get; } public const int QueueLimit = 2000; + // The latest scan's files by stable identity, so the worker can follow a rename without loading every observation. + private readonly Dictionary > identities = []; public Store(string path) { @@ -39,25 +41,59 @@ public Store(string path) private static T Read (string? value) => JsonSerializer.Deserialize (value!)!; public IReadOnlyList Roots() => db.Query("SELECT data FROM roots ORDER BY path").Select(row => Read (row[0])).ToArray(); public void SaveRoot(ManagedFolder root) => db.Query("INSERT INTO roots VALUES(?,?,?) ON CONFLICT(id) DO UPDATE SET path=excluded.path,data=excluded.data", root.Id, root.Path, Json(root)); - public void RemoveRoot(string id) => db.Transaction(() => + public void RemoveRoot(string id) { - Cancel(id, true); - db.Query("DELETE FROM roots WHERE id=?", id); - db.Query("DELETE FROM observations WHERE root=?", id); - db.Query("DELETE FROM decisions WHERE root=?", id); - }); + db.Transaction(() => + { + Cancel(id, true); + db.Query("DELETE FROM roots WHERE id=?", id); + db.Query("DELETE FROM observations WHERE root=?", id); + db.Query("DELETE FROM decisions WHERE root=?", id); + }); + lock (identities) identities.Remove(id); + } public IReadOnlyList Observations(string root) => db.Query("SELECT data FROM observations WHERE root=?", root).Select(row => Read (row[0])).ToArray(); public IReadOnlyList Scans(string? root = null) => db.Query("SELECT data FROM scans WHERE (? IS NULL OR root=?) ORDER BY id DESC LIMIT 500", root, root).Select(row => Read (row[0])).ToArray(); - public void SaveScan(string root, IEnumerable observations, ScanSummary summary) => db.Transaction(() => + /// The latest scan's entry for a file identity, wherever that file has been renamed to.
+ public Observation? Observed(string root, string identity) + { + lock (identities) + { + if (!identities.TryGetValue(root, out var map)) identities[root] = map = Index(Observations(root)); + return map.GetValueOrDefault(identity); + } + } + + private static DictionaryIndex(IEnumerable observations) { - db.Query("DELETE FROM observations WHERE root=?", root); - foreach (var observation in observations) db.Query("INSERT INTO observations VALUES(?,?,?)", root, observation.Path, Json(observation)); - db.Query("INSERT INTO scans(root,time,data) VALUES(?,?,?)", root, summary.Utc.ToString("O"), Json(summary)); - db.Query("DELETE FROM scans WHERE id NOT IN (SELECT id FROM scans ORDER BY id DESC LIMIT 2000)"); - db.Query("DELETE FROM decisions WHERE time < ?", DateTime.UtcNow.AddDays(-90).ToString("O")); - db.Query("DELETE FROM jobs WHERE state NOT IN ('Queued','Retry','Running') AND id NOT IN (SELECT id FROM jobs ORDER BY created DESC LIMIT 10000)"); - }); + var map = new Dictionary (StringComparer.Ordinal); + foreach (var observation in observations) if (observation.File != null) map.TryAdd(observation.File.Identity, observation); + return map; + } + + public void SaveScan(string root, IEnumerable observations, ScanSummary summary) + { + var entries = observations.ToList(); + db.Transaction(() => + { + // Write only what changed: an idle folder's rescan should not rewrite its whole history. + var stored = new Dictionary (StringComparer.OrdinalIgnoreCase); + foreach (var row in db.Query("SELECT path,data FROM observations WHERE root=?", root)) stored[row[0]!] = row[1]!; + foreach (var observation in entries) + { + var data = Json(observation); + if (stored.Remove(observation.Path, out var previous) && previous == data) continue; + db.Query("INSERT INTO observations VALUES(?,?,?) ON CONFLICT(root,path) DO UPDATE SET path=excluded.path,data=excluded.data", root, observation.Path, data); + } + foreach (var gone in stored.Keys) db.Query("DELETE FROM observations WHERE root=? AND path=?", root, gone); + db.Query("INSERT INTO scans(root,time,data) VALUES(?,?,?)", root, summary.Utc.ToString("O"), Json(summary)); + db.Query("DELETE FROM scans WHERE id NOT IN (SELECT id FROM scans ORDER BY id DESC LIMIT 2000)"); + db.Query("DELETE FROM decisions WHERE time < ?", DateTime.UtcNow.AddDays(-90).ToString("O")); + db.Query("DELETE FROM jobs WHERE state NOT IN ('Queued','Retry','Running') AND id NOT IN (SELECT id FROM jobs ORDER BY created DESC LIMIT 10000)"); + }); + lock (identities) identities[root] = Index(entries); + } public IReadOnlyList Jobs() => db.Query("SELECT data FROM jobs ORDER BY created DESC").Select(row => Read (row[0])).ToArray(); public DateTime? RunStart(string root) => diff --git a/src/ZipXP.Core/Services/Analyzer.cs b/src/ZipXP.Core/Services/Analyzer.cs index bca09fe..b4a560f 100644 --- a/src/ZipXP.Core/Services/Analyzer.cs +++ b/src/ZipXP.Core/Services/Analyzer.cs @@ -17,6 +17,10 @@ public sealed class Analyzer(Store store) long logical = 0, allocated = 0, candidates = 0, estimate = 0; int files = 0, unknown = 0, errors = 0, defaults = NativeFiles.Read(root.Path).Compressed ? 1 : 0; var complete = true; + // Sampling reads up to 96 KB per candidate. Reuse the last estimate while a file's content is unchanged. + var estimates = new Dictionary (StringComparer.OrdinalIgnoreCase); + foreach (var previous in store.Observations(root.Id)) + if (previous is { File: { Directory: false } file, EstimatedSaving: long saving }) estimates.TryAdd(previous.Path, (file, saving)); while (pending.TryPop(out var directory)) { token.ThrowIfCancellationRequested(); @@ -53,9 +57,9 @@ public sealed class Analyzer(Store store) long? saving = null; if (reason == null) { - saving = Rules.Estimate(file); - var fresh = NativeFiles.Read(path); - if (!file.SameContent(fresh)) reason = "Changed during sampling; rescan pending"; + var reused = estimates.TryGetValue(path, out var cached) && cached.File.SameContent(file); + saving = reused ? cached.Saving : Rules.Estimate(file); + if (!reused && !file.SameContent(NativeFiles.Read(path))) reason = "Changed during sampling; rescan pending"; else if (saving < root.Policy.MinimumSavingBytes) { reason = "Permanent: low estimated benefit until content changes"; diff --git a/src/ZipXP.Core/Services/Engine.cs b/src/ZipXP.Core/Services/Engine.cs index f4a60e2..9c9b5ff 100644 --- a/src/ZipXP.Core/Services/Engine.cs +++ b/src/ZipXP.Core/Services/Engine.cs @@ -4,7 +4,8 @@ namespace ZipXP.Core.Services; -public sealed record EngineOptions(int ReconcileSeconds = 120, int DebounceMilliseconds = 2000, int ScanSpacingSeconds = 15, int FileDelayMilliseconds = 500); +// Watcher events trigger scans within seconds; the periodic reconciliation scan only catches anything they missed. +public sealed record EngineOptions(int ReconcileSeconds = 1800, int DebounceMilliseconds = 2000, int ScanSpacingSeconds = 15, int FileDelayMilliseconds = 500); public sealed record JobPreview(int Files, long LogicalBytes, long RequiredHeadroom, int NativeDefaults, string Coverage); public sealed class Engine : IAsyncDisposable @@ -233,7 +234,9 @@ public Task CycleAsync() => Exclusive(() => foreach (var root in roots) { var last = scanned.GetValueOrDefault(root.Id, DateTime.MinValue); - if (last.AddSeconds(options.ReconcileSeconds) <= now || (dirty.TryGetValue(root.Id, out var due) && due <= now && (due == DateTime.MinValue || last.AddSeconds(options.ScanSpacingSeconds) <= now))) + // Without a watcher, the periodic scan is the only way to notice changes, so keep it frequent. + var reconcile = watchers.ContainsKey(root.Id) ? options.ReconcileSeconds : Math.Min(options.ReconcileSeconds, 120); + if (last.AddSeconds(reconcile) <= now || (dirty.TryGetValue(root.Id, out var due) && due <= now && (due == DateTime.MinValue || last.AddSeconds(options.ScanSpacingSeconds) <= now))) { // Remove first so events arriving during a scan are retained for the next pass. dirty.TryRemove(root.Id, out _); @@ -275,7 +278,7 @@ public Task CycleAsync() => Exclusive(() => if (waiting != null) { statuses[root.Id] = waiting; waits[root.Id] = (waiting, DateTime.UtcNow); continue; } waits.TryRemove(root.Id, out _); // A rename is reconciled by stable identity. A replacement at the same path is never substituted. - var observation = Store.Observations(root.Id).FirstOrDefault(o => o.File?.Identity == job.Expected.Identity); + var observation = Store.Observed(root.Id, job.Expected.Identity); var executing = observation?.File != null && observation.File.SameContent(job.Expected) ? job with { Expected = job.Expected with { Path = observation.Path } } : job; current = executing.Path; Status = job.Operation + ": " + current; diff --git a/tests/ZipXP.Checks/Program.cs b/tests/ZipXP.Checks/Program.cs index d5264eb..7e1a52e 100644 --- a/tests/ZipXP.Checks/Program.cs +++ b/tests/ZipXP.Checks/Program.cs @@ -192,6 +192,24 @@ private static async Task Run(string fixture, string state) var outOfScope = new Mutator().Execute(root, Job(root, source with { Path = Path.Combine(fixture + "-sibling", "file.txt") }, "Compress")); Check(outOfScope.State != "Succeeded", "sibling-prefix path cannot escape managed root"); + { + // Rescans write only changed observations; renames and deletions must still land. + var tracked = Path.Combine(fixture, "tracked.txt"); Text(tracked); + var identity = NativeFiles.Read(tracked).Identity; + new Analyzer(store).Scan(store.Roots().Single()); + var firstEstimate = store.Observations(root.Id).Single(o => o.Path == tracked).EstimatedSaving; + new Analyzer(store).Scan(store.Roots().Single()); + Check(store.Observations(root.Id).Single(o => o.Path == tracked).EstimatedSaving == firstEstimate, "unchanged rescan keeps the stored estimate"); + var renamed = Path.Combine(fixture, "Tracked-Renamed.txt"); File.Move(tracked, renamed); + new Analyzer(store).Scan(store.Roots().Single()); + var afterRename = store.Observations(root.Id); + Check(afterRename.Any(o => o.Path == renamed) && !afterRename.Any(o => o.Path == tracked) && store.Observed(root.Id, identity)?.Path == renamed, + "rescan records a rename and the worker finds the file by identity"); + File.Delete(renamed); + new Analyzer(store).Scan(store.Roots().Single()); + Check(!store.Observations(root.Id).Any(o => o.Path == renamed) && store.Observed(root.Id, identity) == null, "rescan drops deleted files"); + } + var linkPath = Path.Combine(fixture, "reparse-child"); Junction(linkPath, Path.Combine(fixture, "child")); { diff --git a/website/index.html b/website/index.html index 81889dd..c38dcfd 100644 --- a/website/index.html +++ b/website/index.html @@ -267,7 +267,7 @@ Six steps.
You do three.Add a folder
Pick a local fixed NTFS folder like
C:\Users\you\Projects. Overlapping roots are rejected up front.Read-only analysis
Allocation totals, candidate bytes, largest files, and how many directories already carry Windows' own compression flag.
-Set a policy
Turn on automation, choose subfolders and battery behavior. Advanced options hold thresholds, schedule and reserve.
+Queue
Eligible files join one persistent, sequential queue. File-system notifications and a 2-minute reconciliation scan keep it current.
Queue
Eligible files join one persistent, sequential queue. File-system notifications keep it current, and a 30-minute reconciliation scan catches anything they miss.
Compress
One file at a time, below-normal priority, through a validated native handle. Busy files retry with backoff.
Measure
Actual allocation is read back from the same handle. Poor-benefit files are cached and left alone until their content changes.
@@ -37,7 +37,7 @@
ZipXP needs Windows 11 and a local NTFS drive. Install the latest release for your user (no admin needed) from Windows PowerShell:
```powershell
-curl.exe -fsSL https://kiranscript.github.io/zipxp/install.ps1 -o "$env:TEMP\zipxp-get.ps1"; powershell -NoProfile -ExecutionPolicy Bypass -File "$env:TEMP\zipxp-get.ps1"
+curl.exe -fsSL https://github.com/kiranscript/zipxp/releases/latest/download/zipxp-get.ps1 -o "$env:TEMP\zipxp-get.ps1"; powershell -NoProfile -ExecutionPolicy Bypass -File "$env:TEMP\zipxp-get.ps1"
```
It downloads the release ZIP, verifies its SHA-256 and runs the installer; see [Install and uninstall](docs/install.md) for options and what it does. The React desktop interface requires the [Microsoft Edge WebView2 Runtime](https://developer.microsoft.com/microsoft-edge/webview2/).
@@ -60,7 +60,7 @@ Storage insights lists what takes the room in each folder, with every file's ori