The best way to control Claude Code, Codex and more from any computer or phone

main
astro 220 lines 5.21 KB
Raw
1 ---
2 /**
3 * `<BenchChart />` — one chart from the distilled benchmark dashboard,
4 * rendered at build time from a data snapshot (`data.json`, written by
5 * `distilled-bench-dashboard/scripts/export-blog.mjs`).
6 *
7 * Usage in MDX:
8 * <BenchChart chart="bundle" />
9 */
10 import data from "./data.json";
11 import { fmtBytes, fmtUs, lineChart, type Point, type Ref } from "./lineChart.ts";
12
13 type ChartId = "bundle" | "speed" | "memory" | "providerHeap" | "experiments";
14
15 interface Props {
16 chart: ChartId;
17 /** Draw the official SDKs as dashed reference lines. */
18 official?: boolean;
19 }
20
21 interface Series {
22 points: Point[];
23 second?: (number | null)[];
24 refs?: Ref[];
25 }
26
27 const CHARTS: Record<ChartId, { title: string; sub: string; how: string; series: Series; format: (n: number) => string }> = {
28 bundle: {
29 title: "Bundle size",
30 sub: "median per program · lower is better",
31 how: "Minified rolldown bundle of a program that sets up auth and calls 1 operation, gzip -9.",
32 series: data.bundle as Series,
33 format: fmtBytes,
34 },
35 speed: {
36 title: "Runtime speed",
37 sub: "median per program · lower is better",
38 how: "Added latency: p50 of a call against a mocked HTTP response minus p50 of a bare mocked round trip.",
39 series: data.speed as Series,
40 format: fmtUs,
41 },
42 memory: {
43 title: "Runtime memory",
44 sub: "median per program · lower is better",
45 how: "Import heap: V8 heapUsed after importing the SDK modules, minus before (fresh Node, Effect preloaded).",
46 series: data.memory as Series,
47 format: fmtBytes,
48 },
49 providerHeap: {
50 title: "Heap, provider imported",
51 sub: "total over all providers · lower is better",
52 how: "Retained V8 heap after importing every service module of each provider in a fresh Node process.",
53 series: data.providerHeap as Series,
54 format: fmtBytes,
55 },
56 experiments: {
57 title: "Bundle size",
58 sub: `median over the ${data.experiments.programs} programs every experiment ran · lower is better`,
59 how: "Each experiment is a flat line across the commit timeline.",
60 series: data.experiments.bundle as Series,
61 format: fmtBytes,
62 },
63 };
64
65 const { chart, official = false } = Astro.props;
66 const c = CHARTS[chart];
67 const { legend, svg } = lineChart(c.series.points, {
68 format: c.format,
69 branchLabel: "this work",
70 second: c.series.second ? { label: "strict", values: c.series.second } : undefined,
71 refs: official ? c.series.refs : c.series.refs?.filter((r) => r.kind !== "official"),
72 });
73 ---
74
75 <figure class="bench" data-nosnippet>
76 <figcaption class="bench__head">
77 <span class="bench__title">{c.title}</span>
78 <span class="bench__sub"> · {c.sub}</span>
79 <span class="bench__how">{c.how}</span>
80 </figcaption>
81 <Fragment set:html={legend} />
82 <Fragment set:html={svg} />
83 </figure>
84
85 <style>
86 .bench {
87 margin: 2rem 0;
88 padding: 1.1rem 1.1rem 0.6rem;
89 background: var(--alc-bg-elev-1);
90 border: 1px solid var(--alc-hairline-2);
91 border-radius: 12px;
92 }
93
94 .bench__head {
95 margin-bottom: 0.5rem;
96 line-height: 1.4;
97 }
98
99 .bench__title {
100 font-weight: 700;
101 color: var(--alc-fg-1);
102 }
103
104 .bench__sub {
105 color: var(--alc-fg-4);
106 }
107
108 .bench__how {
109 display: block;
110 margin-top: 0.15rem;
111 font-size: 0.8rem;
112 color: var(--alc-fg-4);
113 }
114
115 .bench :global(.bench-legend) {
116 display: flex;
117 flex-wrap: wrap;
118 gap: 0.2rem 0.9rem;
119 margin: 0 0 0.25rem;
120 font-size: 0.78rem;
121 color: var(--alc-fg-3);
122 }
123
124 .bench :global(.bench-legend span) {
125 display: inline-flex;
126 align-items: center;
127 gap: 0.35rem;
128 }
129
130 .bench :global(svg.sw) {
131 width: 26px;
132 height: 8px;
133 overflow: visible;
134 }
135
136 .bench :global(.bench-svg) {
137 display: block;
138 width: 100%;
139 height: auto;
140 }
141
142 .bench :global(.bench-svg text) {
143 fill: var(--alc-fg-4);
144 font: 12.5px var(--alc-font-mono);
145 }
146
147 .bench :global(.grid-line) {
148 stroke: var(--alc-hairline-2);
149 }
150
151 .bench :global(.branch-zone) {
152 fill: var(--alc-accent-12);
153 }
154
155 .bench :global(.bench-svg .zone-label) {
156 fill: var(--alc-accent-text);
157 }
158
159 .bench :global(.series) {
160 fill: none;
161 stroke: var(--alc-fg-1);
162 stroke-width: 2.5;
163 stroke-linejoin: round;
164 }
165
166 .bench :global(.series.strict) {
167 stroke: var(--alc-info);
168 stroke-width: 2;
169 stroke-dasharray: 0.1 4.5;
170 stroke-linecap: round;
171 }
172
173 .bench :global(.dot) {
174 fill: var(--alc-hairline-3);
175 stroke: var(--alc-bg-elev-1);
176 stroke-width: 1.5;
177 }
178
179 .bench :global(.dot.good) {
180 fill: var(--alc-accent);
181 }
182
183 .bench :global(.dot.bad) {
184 fill: var(--alc-danger);
185 }
186
187 .bench :global(.dot.strict) {
188 fill: var(--alc-bg-elev-1);
189 stroke: var(--alc-info);
190 }
191
192 .bench :global(.ref) {
193 stroke-width: 1.75;
194 stroke-dasharray: 9 5;
195 }
196
197 .bench :global(.ref.official) {
198 stroke-width: 2;
199 stroke-dasharray: 12 4 2 4;
200 }
201
202 .bench :global(.bench-svg .ref-label) {
203 font-weight: 600;
204 paint-order: stroke;
205 stroke: var(--alc-bg-elev-1);
206 stroke-width: 3px;
207 }
208
209 .bench :global(.bench-svg .end-label) {
210 fill: var(--alc-fg-1);
211 font-weight: 600;
212 paint-order: stroke;
213 stroke: var(--alc-bg-elev-1);
214 stroke-width: 3px;
215 }
216
217 .bench :global(.bench-svg .end-label.strict) {
218 fill: var(--alc-info);
219 }
220 </style>