import {
byId,
fetchJson,
fetchText,
formatNumber,
initThemeToggle,
} from "./shared.js";
function fileName(path) {
const chunks = String(path).split("/");
return chunks[chunks.length - 1] || path;
}
function modeLabel(mode) {
return mode === "compiled_aten" ? "compiled+ATEN" : (mode ?? "-");
}
function escapeHtml(text) {
return String(text)
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function normalizePath(path) {
const parts = [];
for (const segment of String(path).split("/")) {
if (!segment || segment === ".") {
continue;
}
if (segment === "..") {
if (parts.length > 0 && parts[parts.length - 1] !== "..") {
parts.pop();
} else {
parts.push("..");
}
continue;
}
parts.push(segment);
}
return parts.join("/");
}
function dirname(path) {
const index = path.lastIndexOf("/");
return index >= 0 ? path.slice(0, index) : "";
}
function isAbsoluteHref(href) {
return /^(?:[a-z]+:|#|\/\/)/i.test(href);
}
function resolveHref(basePath, href) {
const trimmed = String(href).trim();
if (!trimmed) {
return "#";
}
if (isAbsoluteHref(trimmed)) {
return trimmed;
}
let path = trimmed;
let hash = "";
let query = "";
const hashIndex = path.indexOf("#");
if (hashIndex >= 0) {
hash = path.slice(hashIndex);
path = path.slice(0, hashIndex);
}
const queryIndex = path.indexOf("?");
if (queryIndex >= 0) {
query = path.slice(queryIndex);
path = path.slice(0, queryIndex);
}
const base = dirname(basePath);
return normalizePath((base ? `${base}/` : "") + path) + query + hash;
}
function parseInline(markdown, basePath) {
let text = escapeHtml(markdown);
text = text.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_match, alt, href) => {
const resolved = escapeHtml(resolveHref(basePath, href));
return ``;
});
text = text.replace(/`([^`]+)`/g, (_match, code) => `
${code}`);
text = text.replace(/\*\*([^*]+)\*\*/g, "$1");
text = text.replace(/\*([^*]+)\*/g, "$1");
text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, label, href) => {
const resolved = escapeHtml(resolveHref(basePath, href));
return `${escapeHtml(label)}`;
});
return text;
}
function markdownToHtml(markdown, basePath) {
let text = String(markdown).replace(/\r\n/g, "\n");
const codeBlocks = [];
text = text.replace(/```([\w-]*)\n([\s\S]*?)```/g, (_match, lang, code) => {
const index = codeBlocks.length;
const cls = lang ? ` class="language-${escapeHtml(lang)}"` : "";
codeBlocks.push(`
${escapeHtml(code)}`);
return `@@CODEBLOCK_${index}@@`;
});
const lines = text.split("\n");
const html = [];
let paragraph = [];
let inUnorderedList = false;
let inOrderedList = false;
const flushParagraph = () => {
if (paragraph.length === 0) {
return;
}
html.push(`${parseInline(paragraph.join(" "), basePath)}
`); paragraph = []; }; const closeLists = () => { if (inUnorderedList) { html.push(""); inUnorderedList = false; } if (inOrderedList) { html.push(""); inOrderedList = false; } }; for (const rawLine of lines) { const trimmed = rawLine.trim(); if (!trimmed) { flushParagraph(); closeLists(); continue; } const heading = /^(#{1,6})\s+(.+)$/.exec(trimmed); if (heading) { flushParagraph(); closeLists(); const level = heading[1].length; html.push(``); continue; } closeLists(); paragraph.push(trimmed); } flushParagraph(); closeLists(); return html.join("\n").replace(/@@CODEBLOCK_(\d+)@@/g, (_match, index) => codeBlocks[Number(index)] ?? ""); } function renderPaperContext(manifest, rows) { const workload = byId("paper-workload"); const abstract = byId("paper-abstract"); const notes = byId("paper-notes"); const interpretation = byId("paper-interpretation"); if (!workload || !abstract || !notes || !interpretation) { return; } const context = manifest.paper_context ?? {}; workload.textContent = `${context.workload ?? "Workload context unavailable."}${context.goal ? ` Goal: ${context.goal}` : ""}`; notes.innerHTML = ""; for (const note of context.notes ?? []) { const item = document.createElement("li"); item.textContent = note; notes.appendChild(item); } const concurrencyEight = rows.filter((row) => Number(row.concurrency) === 8); const arena = concurrencyEight.find((row) => row.mode === "arena"); const eager = concurrencyEight.find((row) => row.mode === "eager"); const compiled = concurrencyEight.find((row) => row.mode === "compiled_aten"); if (!arena || !eager || !compiled || !arena.latency_ms || !eager.latency_ms || !compiled.latency_ms) { abstract.textContent = "Primary inference rows were not complete enough to compute operating-point deltas."; interpretation.textContent = "Interpretation unavailable because one or more mode/concurrency slices are missing."; return; } const p95VsCompiled = ((arena.latency_ms.p95 - compiled.latency_ms.p95) / compiled.latency_ms.p95) * 100.0; const p99VsCompiled = ((arena.latency_ms.p99 - compiled.latency_ms.p99) / compiled.latency_ms.p99) * 100.0; const p95VsEager = ((arena.latency_ms.p95 - eager.latency_ms.p95) / eager.latency_ms.p95) * 100.0; abstract.textContent = "Under concurrent load, arena mode maintains deterministic memory behavior while preserving near-eager tail latency and materially reducing compiled-path tail inflation. " + `At c=8, arena is ${formatNumber(p95VsCompiled, 2)}% on p95 and ${formatNumber(p99VsCompiled, 2)}% on p99 versus compiled+ATEN (negative means better).`; interpretation.textContent = "This supports a stability-first operating point: arena eliminates post-warmup allocation churn (allocΔ=0, segΔ=0) and keeps tails tight. " + `Against eager at c=8, p95 remains near parity (${formatNumber(p95VsEager, 2)}% delta), so the tradeoff is small while determinism improves significantly.`; } async function renderPrimaryStats(manifest) { const tableBody = byId("inference-table-body"); const points = byId("quick-points"); const latestSource = byId("latest-source"); const primaryLinks = byId("primary-links"); if (!tableBody || !points || !latestSource || !primaryLinks) { return; } latestSource.textContent = `Source JSON: ${manifest.primary_json}`; primaryLinks.innerHTML = `Primary JSON` + ` | Primary SVG`; try { const payload = await fetchJson(manifest.primary_json); const rows = Array.isArray(payload.results) ? payload.results : []; tableBody.innerHTML = ""; points.innerHTML = ""; if (rows.length === 0) { tableBody.innerHTML = `${parseInline(quote[1], basePath)}