Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(usage): cut warm usage scans from seconds to milliseconds on large histories #15149

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/15149/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Showing 9 changed files with 187 additions and 0 deletions (loading 8).

x
0 of 9 viewed, 9 left
187 additions and 0 deletionsapps/server/src/usage/UsageService.test.tsModified
View file
@@ -1,5 +1,6 @@
// @effect-diagnostics nodeBuiltinImport:off - the suite seeds and grows real
// transcript trees on disk, outside the service's Effect FileSystem.
+import * as NodeChildProcess from "node:child_process";
import * as NodeFSP from "node:fs/promises";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";
@@ -117,6 +118,41 @@
​
+/** Outside `NARROW_WINDOW`, inside `WINDOW`. Seconds, as `utimes` takes them. */
+const BEFORE_NARROW_WINDOW = Date.parse("2026-08-01T10:00:00Z") / 1000;
+const NARROW_WINDOW: UsageSummaryInput = {
+ timeZone: "UTC",
+ sinceDay: UsageDay.make("2026-09-01"),
+ untilDay: UsageDay.make("2026-09-02"),
+};
+​
+/**
+ * A FIFO named like a transcript. A scan's read of it waits in `open` until
+ * `openGate`, then fails at once, so a gate holds that scan's directory reads
+ * in flight. Each waiting gate holds one libuv pool thread; keep at most three.
+ */
+const makeGate = (path: string, lastWriteSeconds?: number) =>
+ Effect.promise(async () => {
+ NodeChildProcess.execFileSync("mkfifo", [path]);
+ if (lastWriteSeconds !== undefined) {
+ await NodeFSP.utimes(path, lastWriteSeconds, lastWriteSeconds);
+ }