From 2e56351e9686618c93730d702a80c262eddc6e75 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 20:52:12 +0000 Subject: [PATCH] Benchmarks: lean list queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit listBenchmarks() selected every column of every run, including the raw A/B series, all quality eval items, hardware facts and descriptions, while lists show only the snapshot, settings, headline numbers and the quality score. With 200 runs /api/benchmarks returned 732 KB, re-fetched every 3 s while a run was active; the table used about 55 KB of it. - listBenchmarks() returns lean rows: the headline numbers are computed on the server from the summary, the quality score comes from json_extract(). - The model page asks for 5 runs (it shows 5), the ⌘K index for 300. - getBenchmark()/getBenchmarks() keep the full rows for detail and compare; cancel and delete only read the state. - ListRow (lists) and RunRow (detail) are separate types. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EooZ9biu7kFNB4eDJrwQc5 --- CHANGELOG.md | 3 + src/app/(app)/[org]/[repo]/page.tsx | 8 +-- src/app/(app)/benchmarks/[id]/ab-report.tsx | 4 +- .../benchmarks/[id]/benchmark-detail.tsx | 4 +- .../benchmarks/[id]/benchmark-report.tsx | 4 +- src/app/(app)/benchmarks/benchmark-list.tsx | 19 +++--- src/app/(app)/endpoints/page.tsx | 5 +- src/app/api/search-index/route.ts | 4 +- src/lib/benchmarks.ts | 59 +++++++++++++++---- src/lib/endpoints.test.ts | 35 +++++++++++ 10 files changed, 111 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfc9a24..e943926 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ step 1 (Hugging Face downloader) is released as a minor version. - **Lighter library page**: folders found in the models folder no longer bring their whole file list (up to 5,000 entries each) into the page; **Import** loads it when you click it. Search and filter counts are computed once per change instead of on every progress update. +- **Lighter benchmark lists**: the Benchmarks and Endpoints pages, a model's sidebar and the ⌘K + search load only what they show (headline numbers, the quality score), not every run's full + results; the list refreshed every 3 s during a run now sends a fraction of the data. ## [0.16.0] - 2026-10-30 diff --git a/src/app/(app)/[org]/[repo]/page.tsx b/src/app/(app)/[org]/[repo]/page.tsx index 6d8dd18..8e5f432 100644 --- a/src/app/(app)/[org]/[repo]/page.tsx +++ b/src/app/(app)/[org]/[repo]/page.tsx @@ -26,7 +26,7 @@ import { ModelStatusBadge } from "@/components/model-status-badge"; import { cn } from "@/lib/utils"; import { formatBytes, shortSha } from "@/lib/format"; import { listBenchmarks } from "@/lib/benchmarks"; -import { headline, targetName } from "@/lib/benchmark-view"; +import { targetName } from "@/lib/benchmark-view"; import { fetchModelCard } from "@/lib/hub/client"; import { modelFamilies } from "@/lib/hub/metadata"; import { listModelJobs } from "@/lib/jobs"; @@ -107,7 +107,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o tab === "card" ? fetchModelCard(model.repoId, model.pinnedSha).catch(() => undefined) : Promise.resolve(undefined), getWorkerStatus(), listModelJobs(model.id, 1), - listBenchmarks({ modelId: model.id }), + listBenchmarks({ modelId: model.id }, { limit: 5 }), // the sidebar shows 5 and links to all ]); const update = !hubMissing && model.updateDiff && model.updateDiff.sha === model.remoteSha && model.remoteSha !== model.pinnedSha @@ -306,13 +306,13 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
{runs.slice(0, 5).map((r) => { - const h = headline(r.summary); + const h = r.headline; return ( {r.label ?? targetName(r.snapshot)} - {r.kind === "eval" ? (r.quality?.score != null ? `quality ${r.quality.score}%` : "quality eval") : h.decode != null ? `${h.decode.toFixed(1)} t/s decode` : r.kind === "ab" ? "A/B" : "run"} + {r.kind === "eval" ? (r.qualityScore != null ? `quality ${r.qualityScore}%` : "quality eval") : h.decode != null ? `${h.decode.toFixed(1)} t/s decode` : r.kind === "ab" ? "A/B" : "run"} diff --git a/src/app/(app)/benchmarks/[id]/ab-report.tsx b/src/app/(app)/benchmarks/[id]/ab-report.tsx index 1b9e10d..c9328ff 100644 --- a/src/app/(app)/benchmarks/[id]/ab-report.tsx +++ b/src/app/(app)/benchmarks/[id]/ab-report.tsx @@ -3,7 +3,7 @@ import { abCaveats, abHeadline, abMethod, abSummaryText, halfWidth } from "@/lib import { CONFIG_ROWS, targetName } from "@/lib/benchmark-view"; import type { PairedResult } from "@/lib/db/schema"; import { cn } from "@/lib/utils"; -import type { ListRow } from "../benchmark-list"; +import type { RunRow } from "../benchmark-list"; const sign = (v: number) => `${v > 0 ? "+" : ""}${v.toFixed(2)}%`; @@ -56,7 +56,7 @@ function Side({ label, name, value, unit }: { label: string; name: string; value ); } -export function AbReport({ run }: { run: ListRow }) { +export function AbReport({ run }: { run: RunRow }) { const ab = run.ab; const a = run.snapshot; const b = run.snapshotB; diff --git a/src/app/(app)/benchmarks/[id]/benchmark-detail.tsx b/src/app/(app)/benchmarks/[id]/benchmark-detail.tsx index 4b9b338..583fb8c 100644 --- a/src/app/(app)/benchmarks/[id]/benchmark-detail.tsx +++ b/src/app/(app)/benchmarks/[id]/benchmark-detail.tsx @@ -39,7 +39,7 @@ import { modelName, targetName, } from "@/lib/benchmark-view"; -import type { ListRow } from "../benchmark-list"; +import type { RunRow } from "../benchmark-list"; import { PageHero } from "@/components/hero/page-hero"; import { RunMetaCard } from "@/components/run-meta"; import { @@ -68,7 +68,7 @@ function duration(a: string | null, b: string | null, now: number) { : `${Math.round(s)} s`; } -export function BenchmarkDetail({ initial }: { initial: ListRow }) { +export function BenchmarkDetail({ initial }: { initial: RunRow }) { const router = useRouter(); const [r, setR] = useState(initial); const [now, setNow] = useState(() => Date.now()); diff --git a/src/app/(app)/benchmarks/[id]/benchmark-report.tsx b/src/app/(app)/benchmarks/[id]/benchmark-report.tsx index bc91bde..426aad7 100644 --- a/src/app/(app)/benchmarks/[id]/benchmark-report.tsx +++ b/src/app/(app)/benchmarks/[id]/benchmark-report.tsx @@ -7,7 +7,7 @@ import { f0, f1, isBatched, reportCaveats, reportMethod, reportSubtitle, reportS import { configChips, engineName, modelName } from "@/lib/benchmark-view"; import type { BenchmarkSummary } from "@/lib/db/schema"; import { cn } from "@/lib/utils"; -import type { ListRow } from "../benchmark-list"; +import type { RunRow } from "../benchmark-list"; function Tile({ label, value, unit, note }: { label: string; value: string; unit: string; note: string }) { return ( @@ -54,7 +54,7 @@ const date = (iso: string | null | undefined) => : ""; /** The run's report, after launch80's bench.betterbench.v1 page; every figure is one BetterBench reported. */ -export function BenchmarkReport({ run }: { run: ListRow }) { +export function BenchmarkReport({ run }: { run: RunRow }) { const sum = run.summary; if (!sum) return null; const s = run.snapshot; diff --git a/src/app/(app)/benchmarks/benchmark-list.tsx b/src/app/(app)/benchmarks/benchmark-list.tsx index 88f4894..182ee14 100644 --- a/src/app/(app)/benchmarks/benchmark-list.tsx +++ b/src/app/(app)/benchmarks/benchmark-list.tsx @@ -17,20 +17,23 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import type { BenchmarkRow } from "@/lib/benchmarks"; -import { configChips, describeSettings, engineName, headline, modelName, targetName } from "@/lib/benchmark-view"; +import type { BenchmarkListRow, BenchmarkRow } from "@/lib/benchmarks"; +import { configChips, describeSettings, engineName, modelName, targetName } from "@/lib/benchmark-view"; import { cn } from "@/lib/utils"; -export type ListRow = Omit< - BenchmarkRow, - "createdAt" | "startedAt" | "finishedAt" | "cancelRequestedAt" -> & { +/** A row as it arrives in the browser (dates as ISO strings). */ +type Serialized = Omit & { createdAt: string; startedAt: string | null; finishedAt: string | null; cancelRequestedAt: string | null; }; +/** A run in a list: headline numbers only. */ +export type ListRow = Serialized; +/** A run with everything (detail page). */ +export type RunRow = Serialized; + const MAX_COMPARE = 16; const fmt = (v: number | null | undefined, digits = 1) => v == null ? "–" : v.toFixed(digits); @@ -165,7 +168,7 @@ export function BenchmarkList({ {shown.map((r) => { - const h = headline(r.summary); + const h = r.headline; const s = r.snapshot; return ( {r.kind === "eval" ? ( - {r.quality?.score != null ? `${r.quality.score}% quality` : "–"} + {r.qualityScore != null ? `${r.qualityScore}% quality` : "–"} ) : ( fmt(h.decode) )} diff --git a/src/app/(app)/endpoints/page.tsx b/src/app/(app)/endpoints/page.tsx index cacfba7..04a0fb2 100644 --- a/src/app/(app)/endpoints/page.tsx +++ b/src/app/(app)/endpoints/page.tsx @@ -5,7 +5,6 @@ import { buttonVariants } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { ENGINE_LABEL } from "@/lib/benchmark-meta"; -import { headline } from "@/lib/benchmark-view"; import { listBenchmarks } from "@/lib/benchmarks"; import { listEndpoints } from "@/lib/endpoints"; import { PageHero } from "@/components/hero/page-hero"; @@ -21,8 +20,8 @@ export default async function EndpointsPage() { for (const r of runs) { if (!r.endpointId || r.state !== "completed") continue; const cur = latest.get(r.endpointId) ?? { decode: null, quality: null }; - if (r.kind === "run" && cur.decode == null) cur.decode = headline(r.summary).decode; - if (r.kind === "eval" && cur.quality == null) cur.quality = r.quality?.score ?? null; + if (r.kind === "run" && cur.decode == null) cur.decode = r.headline.decode; + if (r.kind === "eval" && cur.quality == null) cur.quality = r.qualityScore; latest.set(r.endpointId, cur); } diff --git a/src/app/api/search-index/route.ts b/src/app/api/search-index/route.ts index 009daca..f8b1ba8 100644 --- a/src/app/api/search-index/route.ts +++ b/src/app/api/search-index/route.ts @@ -10,11 +10,11 @@ export const dynamic = "force-dynamic"; /** Everything the ⌘K palette can jump to, compact (it filters in the browser). */ export const GET = withAuth(async () => { - const [models, endpoints, runs, tags] = await Promise.all([listLibrary(), listEndpoints(), listBenchmarks(), listTags()]); + const [models, endpoints, runs, tags] = await Promise.all([listLibrary(), listEndpoints(), listBenchmarks({}, { limit: 300 }), listTags()]); return NextResponse.json({ models: models.map((m) => ({ id: m.id, repoId: m.repoId, quants: m.quants, status: m.status, tags: m.tags.map((t) => t.name) })), endpoints: endpoints.map((e) => ({ id: e.id, name: e.name, model: e.model, engine: e.engine ?? e.probe?.engine ?? null })), - benchmarks: runs.slice(0, 300).map((r) => ({ + benchmarks: runs.map((r) => ({ id: r.id, label: r.label, kind: r.kind, diff --git a/src/lib/benchmarks.ts b/src/lib/benchmarks.ts index 8836a5e..cf5082b 100644 --- a/src/lib/benchmarks.ts +++ b/src/lib/benchmarks.ts @@ -1,9 +1,10 @@ import "server-only"; import { rm } from "node:fs/promises"; -import { and, asc, desc, eq, gt, inArray, or } from "drizzle-orm"; +import { and, asc, desc, eq, gt, inArray, or, sql } from "drizzle-orm"; import { z } from "zod"; import { runDir } from "@/lib/benchmark-paths"; import { libraryModelId, modelFor, snapshotOf } from "@/lib/benchmark-snapshot"; +import { headline } from "@/lib/benchmark-view"; import { db } from "@/lib/db/client"; import { BENCHMARK_PHASES, benchmarkLogs, benchmarkRuns, endpoints, QUALITY_SECTIONS } from "@/lib/db/schema"; import { probeEndpoint } from "@/lib/endpoint-probe"; @@ -95,7 +96,8 @@ export async function createBenchmark(input: BenchmarkInput) { return row; } -const listColumns = { +/** Everything about a run: the detail and compare pages, results downloads. */ +const runColumns = { id: benchmarkRuns.id, endpointId: benchmarkRuns.endpointId, modelId: benchmarkRuns.modelId, @@ -123,10 +125,37 @@ const listColumns = { createdAt: benchmarkRuns.createdAt, }; -export type BenchmarkRow = Awaited>[number]; +/** + * What lists show: no A/B series, eval items, hardware facts or descriptions (lists got all of it, + * ~13× what they use, re-fetched every 3 s while a run was active). The summary is read only to + * compute the headline numbers. + */ +const listColumns = { + id: benchmarkRuns.id, + endpointId: benchmarkRuns.endpointId, + endpointBId: benchmarkRuns.endpointBId, + modelId: benchmarkRuns.modelId, + label: benchmarkRuns.label, + kind: benchmarkRuns.kind, + settings: benchmarkRuns.settings, + snapshot: benchmarkRuns.snapshot, + state: benchmarkRuns.state, + phase: benchmarkRuns.phase, + cancelRequestedAt: benchmarkRuns.cancelRequestedAt, + startedAt: benchmarkRuns.startedAt, + finishedAt: benchmarkRuns.finishedAt, + hasReport: benchmarkRuns.hasReport, + createdAt: benchmarkRuns.createdAt, + summary: benchmarkRuns.summary, + qualityScore: sql`json_extract(${benchmarkRuns.quality}, '$.score')`, +}; -export async function listBenchmarks(filter: { endpointId?: string; modelId?: string } = {}) { - return db() +export type BenchmarkRow = NonNullable>>; +export type BenchmarkListRow = Awaited>[number]; + +/** Runs for lists, newest first; `endpointId` matches either side of an A/B. */ +export async function listBenchmarks(filter: { endpointId?: string; modelId?: string } = {}, options: { limit?: number } = {}) { + let query = db() .select(listColumns) .from(benchmarkRuns) .where( @@ -135,23 +164,31 @@ export async function listBenchmarks(filter: { endpointId?: string; modelId?: st filter.modelId ? eq(benchmarkRuns.modelId, filter.modelId) : undefined, ), ) - .orderBy(desc(benchmarkRuns.createdAt)); + .orderBy(desc(benchmarkRuns.createdAt)) + .$dynamic(); + if (options.limit) query = query.limit(options.limit); + return (await query).map(({ summary, ...r }) => ({ ...r, headline: headline(summary) })); } export async function getBenchmark(id: string) { - const [row] = await db().select(listColumns).from(benchmarkRuns).where(eq(benchmarkRuns.id, id)); + const [row] = await db().select(runColumns).from(benchmarkRuns).where(eq(benchmarkRuns.id, id)); return row ?? null; } export async function getBenchmarks(ids: string[]) { if (ids.length === 0) return []; - const rows = await db().select(listColumns).from(benchmarkRuns).where(inArray(benchmarkRuns.id, ids)); - return ids.map((id) => rows.find((r) => r.id === id)).filter((r) => r != null); + const rows = await db().select(runColumns).from(benchmarkRuns).where(inArray(benchmarkRuns.id, ids)); + const byId = new Map(rows.map((r) => [r.id, r])); + return ids.map((id) => byId.get(id)).filter((r) => r != null); +} + +async function runState(id: string) { + return db().query.benchmarkRuns.findFirst({ columns: { id: true, state: true }, where: eq(benchmarkRuns.id, id) }); } /** Queued runs are cancelled right away; a running one is stopped by the worker. */ export async function cancelBenchmark(id: string) { - const run = await getBenchmark(id); + const run = await runState(id); if (!run) throw new BenchmarkError("not_found", "Benchmark not found.", 404); if (run.state === "queued") { await db().update(benchmarkRuns).set({ state: "cancelled", finishedAt: new Date() }).where(and(eq(benchmarkRuns.id, id), eq(benchmarkRuns.state, run.state))); @@ -172,7 +209,7 @@ export async function updateBenchmark(id: string, patch: { label?: string | null /** Deletes the run, its log and its files. Cancel a running one first. */ export async function deleteBenchmark(id: string) { - const run = await getBenchmark(id); + const run = await runState(id); if (!run) throw new BenchmarkError("not_found", "Benchmark not found.", 404); if (run.state === "running") throw new BenchmarkError("busy", "Cancel the run before deleting it.", 409); await db().delete(benchmarkLogs).where(eq(benchmarkLogs.runId, id)); diff --git a/src/lib/endpoints.test.ts b/src/lib/endpoints.test.ts index 23efebd..1751140 100644 --- a/src/lib/endpoints.test.ts +++ b/src/lib/endpoints.test.ts @@ -129,3 +129,38 @@ describe("queuing runs", () => { assert.equal(run!.snapshotB && "model" in run!.snapshotB ? run!.snapshotB.model : null, "Qwen/Qwen3-8B"); }); }); + +describe("listing runs", () => { + it("lists headline numbers and the quality score, not the heavy results", async () => { + const { benchmarkRuns } = M.schema; + const snapshot = { type: "endpoint" as const, endpointName: "x", model: "m", engine: null, engineVersion: null, contextSize: null, hardware: {} }; + const settings = { quick: false, passes: null, warmup: null, phases: [] }; + const summary = { + v: 2, + combined: { decode: 42.5, ttft_p50: 120, itl_low1: null, update_p50: null, update_p99: null }, + single: [], + prefill: [{ target_depth: 4000, skipped: false, pp_med: 900 }], + concurrency: [{ level: 4, ok: 4, requests: 4, aggregate_tps: 150, ttft_p50: null, ttft_p99: null, decode_med: null }], + phases: [], + cacheHits: 0, + betterbenchVersion: "0.6.1", + corpusVersion: "v1", + passes: null, + quick: false, + }; + const quality = { evalSet: "v1", score: 71, sections: [], items: [{ section: "tools" as const, id: "t1", pass: true }], config: { temperature: 0, seed: 1, thinking: false, contextTokens: null } }; + await M.db.db().insert(benchmarkRuns).values([ + { kind: "run", state: "completed", settings, snapshot, summary, createdAt: new Date(Date.now() + 1000) }, + { kind: "eval", state: "completed", settings, snapshot, quality, createdAt: new Date(Date.now() + 2000) }, + ]); + const rows = await M.benchmarks.listBenchmarks(); + const evalRow = rows.find((r) => r.kind === "eval")!; + const runRow = rows.find((r) => r.kind === "run" && r.headline.decode != null)!; + assert.equal(evalRow.qualityScore, 71); + assert.deepEqual(runRow.headline, { decode: 42.5, ttftMs: 120, prefill: { tps: 900, depth: 4000 }, peak: { tps: 150, level: 4 } }); + for (const r of rows) for (const k of ["summary", "quality", "ab", "meta", "metaB", "system", "description", "snapshotB"]) assert.ok(!(k in r), k); + const [newest] = await M.benchmarks.listBenchmarks({}, { limit: 1 }); + assert.equal(newest.id, evalRow.id, "newest first, limited"); + assert.equal((await M.benchmarks.getBenchmark(evalRow.id))!.quality?.items.length, 1, "the detail still has everything"); + }); +});