GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(server): Storage Cleanup sizes leftover worktrees about 4.8x fas… · incognitojam/styal@65e8831

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • storageCleanup.test.ts
    • storageCleanup.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/storageCleanup.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/storageCleanup.test.ts
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,17 +2193,16 @@ describe("storage cleanup reports and local file policies", () => {
21932193
Effect.gen(function* () {
21942194
const fs = yield* FileSystem.FileSystem;
21952195
const storeDir = yield* fs.makeTempDirectoryScoped({ prefix: "pnpm-store-" });
2196+
const measured = (target: string) => (info: FileSystem.File.Info) => ({
2197+
...info,
2198+
// ZFS can change physical allocation between the expectation and the cleanup scan.
2199+
blocks: Option.some(8n),
2200+
dev: store === "other-device" && target === storeDir ? info.dev + 1n : info.dev,
2201+
});
21962202
const measuredFs = {
21972203
...fs,
2198-
stat: (target: string) =>
2199-
fs.stat(target).pipe(
2200-
Effect.map((info) => ({
2201-
...info,
2202-
// ZFS can change physical allocation between the expectation and the cleanup scan.
2203-
blocks: Option.some(8n),
2204-
dev: store === "other-device" && target === storeDir ? info.dev + 1n : info.dev,
2205-
})),
2206-
),
2204+
stat: (target: string) => fs.stat(target).pipe(Effect.map(measured(target))),
2205+
lstat: (target: string) => fs.lstat(target).pipe(Effect.map(measured(target))),
22072206
};
22082207
const { service, worktree, setPolicy } = yield* cleanupFixture().pipe(
22092208
Effect.provideService(FileSystem.FileSystem, measuredFs),
Collapse file

‎apps/server/src/storageCleanup.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/storageCleanup.ts
+26-28Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -386,36 +386,34 @@ const make = Effect.gen(function* () {
386386
let entries = 1;
387387
let bytes = 0;
388388
while (pending.length > 0) {
389-
const target = pending.pop()!;
390-
if (target === skipped) continue;
391-
// Effect's stat follows links. Probe with readLink first to get lstat
392-
// semantics, including skipping dangling links and directory links.
393-
const isLink = yield* fs.readLink(target).pipe(
394-
Effect.as(true),
395-
Effect.catchIf(
396-
(error) =>
397-
error.cause instanceof Error &&
398-
"code" in error.cause &&
399-
error.cause.code === "EINVAL",
400-
() => Effect.succeed(false),
401-
),
389+
const inspected = yield* Effect.forEach(
390+
pending.splice(-8),
391+
// Untraced: this runs once per entry, and a worktree can hold millions.
392+
Effect.fnUntraced(function* (target) {
393+
if (target === skipped) return { target, bytes: 0, names: [] };
394+
const stat = yield* fs.lstat(target);
395+
if (stat.type === "SymbolicLink") return { target, bytes: 0, names: [] };
396+
if ((yield* fs.realPath(target)) !== target) return null;
397+
if (stat.type === "Directory")
398+
return { target, bytes: 0, names: yield* fs.readDirectory(target) };
399+
// Removing a shared hardlink leaves its blocks allocated.
400+
if (stat.type !== "File" || Option.getOrElse(stat.nlink, () => 1n) !== 1n)
401+
return { target, bytes: 0, names: [] };
402+
const bytes = Option.match(stat.blocks, {
403+
onNone: () => Number(stat.size),
404+
onSome: (blocks) => Number(blocks * 512n),
405+
});
406+
return { target, bytes, names: [] };
407+
}),
408+
{ concurrency: "unbounded" },
402409
);
403-
if (isLink) continue;
404-
if ((yield* fs.realPath(target)) !== target) return null;
405-
const stat = yield* fs.stat(target);
406-
if (stat.type === "File") {
407-
// Removing a shared hardlink leaves its blocks allocated.
408-
if (Option.getOrElse(stat.nlink, () => 1n) !== 1n) continue;
409-
bytes += Option.match(stat.blocks, {
410-
onNone: () => Number(stat.size),
411-
onSome: (blocks) => Number(blocks * 512n),
412-
});
413-
} else if (stat.type === "Directory") {
414-
const names = yield* fs.readDirectory(target);
415-
entries += names.length;
410+
for (const result of inspected) {
411+
if (result === null) return null;
412+
bytes += result.bytes;
413+
entries += result.names.length;
416414
if (entries > 2_000_000) return null;
417-
for (const name of names) {
418-
const child = path.join(target, name);
415+
for (const name of result.names) {
416+
const child = path.join(result.target, name);
419417
if (!inside(root, child)) return null;
420418
pending.push(child);
421419
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.