Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit a8adf7a2e7ae02ae876a6ce7dc28823841f38f97
parent 7bcc59f6eeb87d5805fc81954c51b276ad5002ae
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sun, 25 Oct 2026 01:07:55 -0400

umtool: bounded, one-entry-per-path memos (lib/pathCache.mjs) for the idle heap

The module memos keyed themselves by path+mtime, so every change to a file
added an entry beside the old one and nothing let go. lib/pathCache.mjs keys
by path with the file's signature as a field (a new signature replaces the
entry, a stale read frees it) and bounds count and bytes, LRU out first.
Applied to report.mjs cueMemo and containerMemo, media.ts analyses,
loudness, provenance plans, browse probes, the ASR words cache, and the
article record-meta and channel-posts memos.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Meditor/CHANGELOG.md | 1+
Mumtool/lib/articles/article.ts | 17++++++++++-------
Mumtool/lib/browse.ts | 11+++++++----
Mumtool/lib/clips.ts | 9+++++++--
Mumtool/lib/loudness.ts | 12++++++++----
Mumtool/lib/media.ts | 15+++++++++++----
Aumtool/lib/pathCache.mjs | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/lib/pathCache.test.mjs | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/projects/report.mjs | 36+++++++++++++++++++++++++-----------
Mumtool/lib/provenance.ts | 11+++++++----
10 files changed, 242 insertions(+), 36 deletions(-)

diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## [Unreleased] +- **umtool's memory no longer creeps up while it sits open.** Its in-memory copies of cue files, track analyses, loudness numbers, media probes, ASR word lists, plans and post archives each keep one copy per file (a changed file replaces its old copy) and a bounded number of files, instead of a new copy beside the old every time a file changed. Needs a restart of umtool. - **A take of part of a cut (`--at`) no longer refuses to build over the on-screen deck's markers and claim checks.** The take keeps the markers and claims that follow clips inside its window and drops the rest; a goalpost whose steps cross the window's edge keeps the steps inside it. Needs a restart of umtool. - **umtool's "check every source" step no longer asks for what is already on disk, and no longer bursts a platform.** A source whose clips are all held locally (the build's cache, the editor's window cache, a saved recording) is marked **held locally** and costs no request. The rest are probed one at a time per platform, at least 30 s apart (Rumble 120 s), the same floor the editor's clip fetches keep. When a platform refuses a probe (403, 429, a bot check) umtool stops asking it and marks its remaining sources **not checked**, an info card in the Inbox ("Re-check later"), never "can't be fetched", and it does not stop the build. Needs a restart of umtool. - **A report video can set a subject's own claims against the record on its timeline.** A count claim (`“less than ten” in a year`) draws a band over the dates it is about on the on-screen panel's timeline, dims the rest of the timeline, lights each clip that carries the counter's stamps in date order with its count under it, and counts up to the total under his words in the panel (`19 seizures on camera`). With a **per** (a day, a week, a month) it lights every span that holds that many or more instead (`12 in a day`, `4 in a week`). A goalpost (`“3–5 weeks”` → `“6–8 weeks”`) draws a hollow bracket over the dates each deadline implies; when he moves it, the old one stays dashed and a copy of it moves to the new dates, off the timeline's end with the dates written when they are past its last clip. The finale's large timeline shows every claim at the end. A stamp can be dated by the day the event happened rather than the clip's day (**happened** in the clip editor's Marks). In umtool: the On-screen section's **claim checks** (beside the markers), with **use the playhead** and the build's own checks shown as each field is typed. From a terminal: `umtool look <project> deck.claims='[…]'` and `umtool set <project> <clip> claim.eventDate=2026-09-22`. When the record does not contradict a claim the build prints a note. A video without claims builds exactly as before. Needs a restart of umtool and a rebuild of the video. diff --git a/umtool/lib/articles/article.ts b/umtool/lib/articles/article.ts @@ -13,6 +13,7 @@ import { readAllPosts } from "yt-dlp-transcript-common/lib/posts-server"; import type { Post } from "yt-dlp-transcript-common/lib/posts"; import { readCues } from "@/lib/projects/report.mjs"; import { CHANNELS_DIR } from "@/lib/paths"; +import { pathCache } from "@/lib/pathCache.mjs"; // A report's PAGE VIEW, built the way the export site builds it // (common/lib/report/views.ts buildReportPageView) but resolved against what @@ -40,7 +41,8 @@ export const recordDir = (channel: string, id: string) => type RecordMeta = { title?: string; date?: string; channelTitle?: string; webpageUrl?: string }; -const metaMemo = new Map<string, { key: string; value: RecordMeta | null }>(); +// One entry per metadata file, a bounded number of them (lib/pathCache.mjs). +const metaMemo = pathCache<RecordMeta | null>({ max: 4096 }); /** What a record says about itself; null when its directory holds neither file. */ export async function recordMeta(channel: string, id: string): Promise<RecordMeta | null> { @@ -56,8 +58,7 @@ export async function recordMeta(channel: string, id: string): Promise<RecordMet const st = await stat(/* turbopackIgnore: true */ file).catch(() => null); if (!st) return null; const key = `${Math.round(st.mtimeMs)}-${st.size}`; - const hit = metaMemo.get(file); - if (hit?.key === key) return hit.value; + if (metaMemo.has(file, key)) return metaMemo.get(file, key) ?? null; let value: RecordMeta | null = null; try { const m = JSON.parse(await readFile(/* turbopackIgnore: true */ file, "utf8")); @@ -70,20 +71,22 @@ export async function recordMeta(channel: string, id: string): Promise<RecordMet } catch { value = null; } - metaMemo.set(file, { key, value }); + metaMemo.set(file, key, value); return value; } // A channel's posts, by id. A big X archive is thousands of posts, so one read -// per channel per minute. -const postsMemo = new Map<string, { at: number; value: Promise<Map<string, Post>> }>(); +// per channel per minute -- and at most 8 channels held (lib/pathCache.mjs), +// least recently read out first, so a minute-old archive nobody asks for again +// is not kept for the life of the process. +const postsMemo = pathCache<{ at: number; value: Promise<Map<string, Post>> }>({ max: 8 }); export function channelPosts(channel: string, o: { fresh?: boolean } = {}): Promise<Map<string, Post>> { const hit = postsMemo.get(channel); if (hit && !o.fresh && Date.now() - hit.at < 60_000) return hit.value; const value = readAllPosts(path.join(/* turbopackIgnore: true */ CHANNELS_DIR, channel)) .then((list) => new Map(list.map((p) => [p.id, p]))) .catch(() => new Map<string, Post>()); - postsMemo.set(channel, { at: Date.now(), value }); + postsMemo.set(channel, "", { at: Date.now(), value }); return value; } diff --git a/umtool/lib/browse.ts b/umtool/lib/browse.ts @@ -8,6 +8,7 @@ import { songIdsUnder } from "./projects/song-ids.mjs"; import { REPORTS_ROOT } from "./paths"; import type { CutName } from "./project-types"; import { acceptedFor, readThumbAccepted, type ThumbDoc } from "./thumbs"; +import { fileSig, pathCache } from "./pathCache.mjs"; // --------------------------------------------------------------------------- // The deliverables tree, read as a browsable thing. @@ -415,7 +416,9 @@ export function summarise(s: Song): SongSummary { // else inherits a staleness it did not ask for. // --------------------------------------------------------------------------- -const probes = new Map<string, MediaInfo>(); +// One probe per file (lib/pathCache.mjs): a re-rendered file replaces its old +// answer rather than keeping it beside the new one. +const probes = pathCache<MediaInfo>({ max: 2048 }); export async function probeCached(abs: string): Promise<MediaInfo | null> { let st; @@ -424,12 +427,12 @@ export async function probeCached(abs: string): Promise<MediaInfo | null> { } catch { return null; } - const key = `${abs}|${Math.round(st.mtimeMs)}|${st.size}`; - const hit = probes.get(key); + const sig = fileSig(st); + const hit = probes.get(abs, sig); if (hit) return hit; try { const info = await probeMedia(abs); - probes.set(key, info); + probes.set(abs, sig, info); return info; } catch { return null; diff --git a/umtool/lib/clips.ts b/umtool/lib/clips.ts @@ -9,6 +9,7 @@ import { clipWindow } from "../song/clipwindow.mjs"; import { stripTrailingPop } from "../song/deplosive.mjs"; import { scoreWith } from "../song/orderfeat.mjs"; import { DELIBERATE_CODES } from "../song/reasons.mjs"; +import { pathCache } from "./pathCache.mjs"; export const keyOf = (c: { video: string; start: number }) => `${c.video}@${(+c.start).toFixed(2)}`; @@ -66,7 +67,11 @@ async function loadManifest(): Promise<Map<string, ManifestItem>> { return new Map((m.items ?? []).map((it) => [it.k, it])); } -const asrCache = new Map<string, AsrWord[]>(); +// An episode's ASR words, by video: at most 48 episodes and ~64 MB of words +// (lib/pathCache.mjs), least recently read out first -- a walk over every +// episode (the phrase index, a find across the song) no longer keeps every +// word list for the life of the process. +const asrCache = pathCache<AsrWord[]>({ max: 48, maxBytes: 64 * 1024 * 1024, sizeOf: (w) => w.length * 96 }); export async function wordsFor(video: string): Promise<AsrWord[]> { const hit = asrCache.get(video); @@ -89,7 +94,7 @@ export async function wordsFor(video: string): Promise<AsrWord[]> { */ export function primeWords(video: string, words: AsrWord[]): AsrWord[] { const sorted = words.slice().sort((a, b) => a.start - b.start); - asrCache.set(video, sorted); + asrCache.set(video, "", sorted); return sorted; } diff --git a/umtool/lib/loudness.ts b/umtool/lib/loudness.ts @@ -4,6 +4,7 @@ import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises"; import path from "node:path"; import { CACHE_DIR, labelFor } from "./paths"; import type { Loudness } from "./loudness-types"; +import { pathCache } from "./pathCache.mjs"; export * from "./loudness-types"; @@ -112,7 +113,10 @@ const cacheKey = (abs: string, mtimeMs: number, size: number) => createHash("sha1").update(`${abs}|${Math.round(mtimeMs)}|${size}|loud-v1`).digest("hex").slice(0, 16); const LOUD_CACHE = path.join(CACHE_DIR, "loudness"); -const memo = new Map<string, Loudness>(); +// One measurement per file (lib/pathCache.mjs), its signature the cache key +// (which hashes the file's mtime and size): a re-rendered file replaces its +// old numbers rather than keeping them beside the new ones. +const memo = pathCache<Loudness>({ max: 512 }); async function cacheFileFor(abs: string): Promise<{ key: string; file: string } | null> { let st; @@ -135,11 +139,11 @@ async function cacheFileFor(abs: string): Promise<{ key: string; file: string } export async function cachedLoudness(abs: string): Promise<Loudness | null> { const c = await cacheFileFor(abs); if (!c) return null; - const hit = memo.get(c.key); + const hit = memo.get(abs, c.key); if (hit) return hit; try { const cached = JSON.parse(await readFile(c.file, "utf8")) as Loudness; - memo.set(c.key, cached); + memo.set(abs, c.key, cached); return cached; } catch { return null; @@ -162,7 +166,7 @@ export async function measureLoudness(abs: string): Promise<Loudness> { const tmp = `${c.file}.tmp-${process.pid}`; await writeFile(tmp, JSON.stringify(out)); await rename(tmp, c.file).catch(() => {}); - memo.set(c.key, out); + memo.set(abs, c.key, out); } return out; } diff --git a/umtool/lib/media.ts b/umtool/lib/media.ts @@ -7,6 +7,7 @@ import { existsSync } from "node:fs"; import path from "node:path"; import { MEDIA_ROOT, MEDIA_ROOTS, MEDIA_TIERED, MIX_CACHE, REPORTS_ROOT, SONG_REPORTS, inside, labelFor } from "./paths"; import { brightnessCurve, brightnessSteps } from "../song/flatness.mjs"; +import { fileSig, pathCache } from "./pathCache.mjs"; const run = promisify(execFile); @@ -273,20 +274,26 @@ async function decodeMono(abs: string): Promise<Float32Array> { const cacheKey = (abs: string, mtimeMs: number, size: number) => createHash("sha1").update(`${abs}|${Math.round(mtimeMs)}|${size}|v3`).digest("hex").slice(0, 16); -const memo = new Map<string, Analysis>(); +// In memory: ONE analysis per file (lib/pathCache.mjs), its signature the +// file's mtime and size -- a re-rendered track replaces its old analysis +// rather than keeping it beside the new one -- and at most 64 MB of curves (a +// number is 8 bytes) across 64 tracks. The disk cache below is the long one. +const analysisBytes = (a: Analysis) => 8 * (a.peak.length + a.ratio.length + a.flux.length + 2 * a.steps.length) + 256; +const memo = pathCache<Analysis>({ max: 64, maxBytes: 64 * 1024 * 1024, sizeOf: analysisBytes }); /** Envelope + brightness for a whole track. Cached on disk, keyed by mtime. */ export async function analyseMedia(abs: string): Promise<Analysis> { const st = await stat(abs); const key = cacheKey(abs, st.mtimeMs, st.size); - const hit = memo.get(key); + const sig = fileSig(st); + const hit = memo.get(abs, sig); if (hit) return hit; const file = path.join(MIX_CACHE, `${key}.json`); if (existsSync(file)) { try { const cached = JSON.parse(await readFile(file, "utf8")) as Analysis; - memo.set(key, cached); + memo.set(abs, sig, cached); return cached; } catch { /* rewrite it below */ @@ -357,6 +364,6 @@ export async function analyseMedia(abs: string): Promise<Analysis> { const tmp = `${file}.tmp-${process.pid}`; await writeFile(tmp, JSON.stringify(out)); await rename(tmp, file).catch(() => {}); - memo.set(key, out); + memo.set(abs, sig, out); return out; } diff --git a/umtool/lib/pathCache.mjs b/umtool/lib/pathCache.mjs @@ -0,0 +1,101 @@ +// pathCache — the one shape for a module-level memo of something read from a +// file: ONE entry per key (a path, a video id), bounded by count and by bytes, +// least recently used first out. +// +// Why it exists (umtool's idle heap kept growing): the memos keyed themselves +// by `path|mtime|size`, so every change to a file ADDED an entry beside the +// old one and nothing ever let go -- a corpus that keeps moving (re-synced +// captions, a manifest saved from the bench) left every stale version of +// every cue file parsed in the heap until a restart. Here the key is the path +// and the file's signature (`mtime|size`) is a field of the entry: a new +// signature REPLACES the entry, a read with a stale one is a miss that frees +// it, and the count/byte bounds keep even a walk over the whole corpus from +// holding all of it. +// +// Plain ESM with JSDoc types: node --test, the CLI and the Next server all +// import it. + +/** + * @template V + * @typedef {{ + * get(key: string, sig?: string): V | undefined, + * has(key: string, sig?: string): boolean, + * set(key: string, sig: string, value: V, bytes?: number): V, + * delete(key: string): void, + * clear(): void, + * readonly size: number, + * readonly bytes: number, + * }} PathCache + */ + +/** + * @template V + * @param {{ max?: number, maxBytes?: number, sizeOf?: (value: V) => number }} [opts] + * `max` entries at most (default 256); `maxBytes` of their sizes at most + * (default unbounded) -- each entry's size is the `bytes` given to `set`, + * else `sizeOf(value)`, else 0. The newest entry is kept even when it alone + * is over `maxBytes`: a cache that cannot hold the file it was just asked + * for would read it again on every call. + * @returns {PathCache<V>} + */ +export function pathCache({ max = 256, maxBytes = Infinity, sizeOf } = {}) { + /** @type {Map<string, { sig: string, value: V, bytes: number }>} */ + const entries = new Map(); + let bytes = 0; + /** @param {string} key */ + const drop = (key) => { + const e = entries.get(key); + if (!e) return; + bytes -= e.bytes; + entries.delete(key); + }; + /** @param {string} key @param {string} sig */ + const live = (key, sig) => { + const e = entries.get(key); + if (!e) return undefined; + // A stale signature is the file changed under us: the old value is let go now. + if (e.sig !== sig) { + drop(key); + return undefined; + } + // Most recently used last, so the first key is the one to evict. + entries.delete(key); + entries.set(key, e); + return e; + }; + return { + get(key, sig = "") { + return live(key, sig)?.value; + }, + has(key, sig = "") { + return live(key, sig) !== undefined; + }, + set(key, sig, value, size) { + drop(key); + const n = Number(size ?? (sizeOf ? sizeOf(value) : 0)); + const b = Number.isFinite(n) && n > 0 ? n : 0; + entries.set(key, { sig, value, bytes: b }); + bytes += b; + while (entries.size > max || (bytes > maxBytes && entries.size > 1)) { + const oldest = entries.keys().next().value; + if (oldest === undefined || oldest === key) break; + drop(oldest); + } + return value; + }, + delete: drop, + clear() { + entries.clear(); + bytes = 0; + }, + get size() { + return entries.size; + }, + get bytes() { + return bytes; + }, + }; +} + +/** A file's signature for a pathCache entry: its mtime (ms, rounded) and size. */ +export const fileSig = (/** @type {{ mtimeMs: number, size: number }} */ st) => `${Math.round(st.mtimeMs)}|${st.size}`; diff --git a/umtool/lib/pathCache.test.mjs b/umtool/lib/pathCache.test.mjs @@ -0,0 +1,65 @@ +// lib/pathCache.mjs: one entry per key, a new signature replaces the old, and +// the count and byte bounds evict the least recently used. And the memo it +// was made for: report.mjs readCues keeps ONE parse per cue file however often +// the file changes. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import test from "node:test"; +import { mkdtemp, rm, utimes, writeFile } from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; + +import { fileSig, pathCache } from "./pathCache.mjs"; +import { cueMemoStats, readCues } from "./projects/report.mjs"; + +test("a new signature replaces the entry; a stale read is a miss that frees it", () => { + const c = pathCache(); + c.set("/a.json", "1|10", "first", 10); + assert.equal(c.get("/a.json", "1|10"), "first"); + c.set("/a.json", "2|10", "second", 10); + assert.equal(c.size, 1, "one entry per path, never one per version"); + assert.equal(c.bytes, 10); + assert.equal(c.get("/a.json", "1|10"), undefined); + assert.equal(c.size, 0, "the stale version is let go"); + assert.equal(c.bytes, 0); +}); + +test("bounded by count and by bytes, least recently used out first; the newest is always kept", () => { + const c = pathCache({ max: 3, maxBytes: 100 }); + c.set("a", "", 1, 10); + c.set("b", "", 2, 10); + c.set("c", "", 3, 10); + c.get("a"); // a is now the most recent + c.set("d", "", 4, 10); + assert.deepEqual(["a", "b", "c", "d"].filter((k) => c.has(k)), ["a", "c", "d"], "b, the least recent, went"); + c.set("big", "", 5, 95); + assert.deepEqual(["a", "c", "d", "big"].filter((k) => c.has(k)), ["big"], "evicted down to the byte bound"); + c.set("huge", "", 6, 500); + assert.equal(c.get("huge"), 6, "one entry over the bound alone is still kept"); + assert.equal(c.size, 1); + const s = pathCache({ sizeOf: (v) => v.length }); + s.set("x", "", "abcd"); + assert.equal(s.bytes, 4); +}); + +test("fileSig is mtime (rounded) and size", () => { + assert.equal(fileSig({ mtimeMs: 1234.6, size: 9 }), "1235|9"); +}); + +test("readCues holds one parse per cue file across many changes to it", async () => { + const dir = await mkdtemp(path.join(os.tmpdir(), "cue-memo-")); + try { + const file = path.join(dir, "transcript.cues.json"); + const before = cueMemoStats().size; + for (let i = 0; i < 25; i++) { + await writeFile(file, JSON.stringify({ title: `v${i}`, cues: [{ start: 0, end: 1, text: `line ${i}.` }] })); + await utimes(file, 1_700_000_000 + i, 1_700_000_000 + i); + const doc = await readCues(file); + assert.equal(doc.title, `v${i}`, "the current version, never a stale one"); + } + assert.equal(cueMemoStats().size - before, 1, "25 versions of one file: one entry"); + } finally { + await rm(dir, { recursive: true, force: true }); + } +}); diff --git a/umtool/lib/projects/report.mjs b/umtool/lib/projects/report.mjs @@ -38,6 +38,7 @@ const segmentDirs = (outDir) => [ ]; import { adjudicationGaps, ledgerTotals, unadjudicatedOf } from "umtool-report-to-video/ledger-totals"; import { widen } from "umtool-report-to-video/resolve-windows"; +import { fileSig, pathCache } from "../pathCache.mjs"; // widen() and the cache's window naming are IMPORTED, never reimplemented. The // bench's "extend to sentence end" has to be the same function the CLI runs, or @@ -503,15 +504,16 @@ export const clipWindowDirs = async ( return out; }; -// The container's own answer, for a record whose cues carry no duration. -const containerMemo = new Map(); +// The container's own answer, for a record whose cues carry no duration. One +// entry per file (lib/pathCache.mjs): a changed file replaces its answer. +const containerMemo = pathCache({ max: 1024 }); async function probeContainerMemo(file) { const st = await stat0(file); if (!st) return null; - const key = `${file}|${Math.round(st.mtimeMs)}|${st.size}`; - if (containerMemo.has(key)) return containerMemo.get(key); + const sig = fileSig(st); + if (containerMemo.has(file, sig)) return containerMemo.get(file, sig); const info = await ffprobeSource(file); - containerMemo.set(key, info); + containerMemo.set(file, sig, info); return info; } @@ -526,16 +528,28 @@ export const cuePathFor = (m, e, channelsDir) => { // Cue files are the expensive input: a nine-hour stream's cues run to megabytes, // and six reports citing thirteen videos each would be a hundred-odd megabytes of // JSON on every index load. So the DERIVED answers are memoised against the -// file's own mtime and size -- a cue file is an archive artefact and does not -// change under us, so a hit is permanent in practice. +// file's own mtime and size -- a cue file is an archive artefact and rarely +// changes under us, so a hit is nearly permanent. +// +// ONE ENTRY PER FILE, and a bounded number of them (lib/pathCache.mjs): the +// memo used to key by path+mtime, so every re-synced cue file kept its old +// parse beside the new one for the life of the process -- the idle heap +// growing with nothing open. Now a changed file replaces its entry, and the +// least recently read go first past CUE_MEMO_BYTES of cue files (the parsed +// cues run a few times their file's bytes). // --------------------------------------------------------------------------- -const cueMemo = new Map(); +export const CUE_MEMO_MAX = 512; +export const CUE_MEMO_BYTES = 32 * 1024 * 1024; +const cueMemo = pathCache({ max: CUE_MEMO_MAX, maxBytes: CUE_MEMO_BYTES }); + +/** How many cue files the memo holds, and their bytes on disk (for the tests and a heap check). */ +export const cueMemoStats = () => ({ size: cueMemo.size, bytes: cueMemo.bytes }); export async function readCues(file) { const st = await stat0(file); if (!st) return null; - const key = `${file}|${Math.round(st.mtimeMs)}|${st.size}`; - const hit = cueMemo.get(key); + const sig = fileSig(st); + const hit = cueMemo.get(file, sig); if (hit) return hit; let doc; try { @@ -563,7 +577,7 @@ export async function readCues(file) { ? 0 : cues.filter((c) => ENDS_SENTENCE.test(c.text ?? "")).length / cues.length, }; - cueMemo.set(key, value); + cueMemo.set(file, sig, value, st.size); return value; } diff --git a/umtool/lib/provenance.ts b/umtool/lib/provenance.ts @@ -4,6 +4,7 @@ import { songDir } from "./browse"; import { readState, readJson, type SongState } from "./state"; import { stateFile } from "./paths"; import { archiveMomentUrl } from "./archive"; +import { fileSig, pathCache } from "./pathCache.mjs"; // --------------------------------------------------------------------------- // Where every note in a finished cut came from. @@ -81,7 +82,9 @@ const clipIdOf = (video: string, srcStart: number) => `${video}@${srcStart.toFix // writer and a cached pile would show judgements that have since moved. // --------------------------------------------------------------------------- -const parsed = new Map<string, ProvRow[]>(); +// One parse per plan (lib/pathCache.mjs): a re-rendered plan replaces its old +// rows instead of keeping them beside the new ones, and at most 16 plans. +const parsed = pathCache<ProvRow[]>({ max: 16 }); async function memo(abs: string, parse: (text: string) => ProvRow[]): Promise<ProvRow[]> { let st; @@ -90,8 +93,8 @@ async function memo(abs: string, parse: (text: string) => ProvRow[]): Promise<Pr } catch { return []; } - const key = `${abs}|${Math.round(st.mtimeMs)}|${st.size}`; - const hit = parsed.get(key); + const sig = fileSig(st); + const hit = parsed.get(abs, sig); if (hit) return hit; let rows: ProvRow[] = []; try { @@ -100,7 +103,7 @@ async function memo(abs: string, parse: (text: string) => ProvRow[]): Promise<Pr rows = []; } rows.sort((a, b) => a.songTime - b.songTime); - parsed.set(key, rows); + parsed.set(abs, sig, rows); return rows; }