@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
astro 396 lines 14.2 KB
Raw
1 ---
2 /**
3 * `<BarrelFigure />` — what one root import of `effect` costs in Node.
4 * Tiles: the 138 modules effect 4.0.0 re-exports from `dist/index.js`.
5 * 42 of them are reachable from `effect/Effect` + `effect/Predicate`
6 * (static import graph of the same dist). Heap (3,346 KB vs 9 KB) and
7 * import time (36 ms) are the measured costs of `core/src/error-category.ts`;
8 * each tile's share of them is scaled by its file size on disk.
9 *
10 * One instance per page: element ids are prefixed `br-`.
11 */
12 ---
13
14 <figure class="br not-content" id="br" aria-label="Modules loaded by a root import of effect, then by direct imports">
15 <div class="br-body">
16 <div class="br-side">
17 <pre class="br-code" id="br-code"></pre>
18 <div class="br-stat">
19 <span class="br-k">Heap this line adds</span>
20 <span class="br-v" id="br-heap">0 KB</span>
21 </div>
22 <div class="br-track"><div class="br-fill" id="br-fill"></div></div>
23 <div class="br-stats2">
24 <div class="br-stat"><span class="br-k">Modules loaded</span><span class="br-v" id="br-n">0</span></div>
25 <div class="br-stat"><span class="br-k">Import time</span><span class="br-v" id="br-ms">0 ms</span></div>
26 </div>
27 </div>
28 <div class="br-right">
29 <div class="br-hd"><b>effect</b> · 138 modules</div>
30 <div class="br-grid" id="br-grid"></div>
31 <div class="br-foot">
32 <span class="br-legend"><i class="br-sw need"></i>needed <i class="br-sw extra"></i>not needed</span>
33 <button type="button" id="br-replay">↻ Replay</button>
34 </div>
35 </div>
36 </div>
37 </figure>
38
39 <style is:global>
40 .br {
41 --br-fg: var(--alc-fg-1);
42 --br-mut: var(--alc-fg-4);
43 --br-bg: var(--alc-bg-elev-1);
44 --br-panel: var(--alc-bg-elev-2);
45 --br-bd: var(--alc-hairline-2);
46 --br-bd2: var(--alc-hairline-3);
47 --br-need: var(--alc-info);
48 --br-extra: var(--alc-terracotta);
49 margin: 2rem 0;
50 overflow: hidden;
51 font: 14px/1.5 var(--alc-font-sans);
52 color: var(--br-fg);
53 background: var(--br-bg);
54 border: 1px solid var(--br-bd);
55 border-radius: 12px;
56 }
57 .br * {
58 box-sizing: border-box;
59 }
60 .br code {
61 font-family: var(--alc-font-mono);
62 font-size: 0.9em;
63 }
64 .br button {
65 all: unset;
66 cursor: pointer;
67 padding: 4px 11px;
68 font-size: 13px;
69 font-weight: 600;
70 white-space: nowrap;
71 color: var(--br-fg);
72 background: var(--br-bg);
73 border: 1px solid var(--br-bd2);
74 border-radius: 7px;
75 }
76 .br button:focus-visible {
77 outline: 2px solid var(--alc-accent);
78 }
79 .br-body {
80 display: grid;
81 grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr);
82 gap: 14px;
83 padding: 12px;
84 }
85 .br-side {
86 display: flex;
87 flex-direction: column;
88 gap: 6px;
89 min-width: 0;
90 }
91 .br-code {
92 margin: 0 0 6px;
93 min-height: calc(4 * 17px + 18px);
94 padding: 8px 10px;
95 overflow-x: auto;
96 font: 11.5px/17px var(--alc-font-mono);
97 color: var(--br-fg);
98 white-space: pre;
99 background: var(--br-panel);
100 border: 1px solid var(--br-bd);
101 border-radius: 8px;
102 }
103 .br-code .old {
104 color: var(--br-extra);
105 text-decoration: line-through;
106 }
107 .br-code .new {
108 color: var(--alc-accent-text);
109 animation: brtype 0.5s steps(14) both;
110 display: inline-block;
111 overflow: hidden;
112 vertical-align: bottom;
113 }
114 @keyframes brtype {
115 from {
116 max-width: 0;
117 }
118 to {
119 max-width: 20ch;
120 }
121 }
122 .br-code .s {
123 color: var(--alc-accent-text);
124 }
125 .br-code .k {
126 color: var(--br-mut);
127 }
128 .br-stat {
129 display: flex;
130 flex-direction: column;
131 min-width: 0;
132 }
133 .br-k {
134 font-size: 11.5px;
135 color: var(--br-mut);
136 }
137 .br-v {
138 font: 700 20px/1.2 var(--alc-font-mono);
139 font-variant-numeric: tabular-nums;
140 }
141 .br-track {
142 position: relative;
143 height: 14px;
144 overflow: hidden;
145 background: color-mix(in srgb, var(--br-mut) 14%, transparent);
146 border-radius: 3px;
147 }
148 .br-fill {
149 transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
150 position: absolute;
151 top: 0;
152 bottom: 0;
153 left: 0;
154 width: var(--pct, 0%);
155 min-width: var(--min, 0);
156 background: var(--br-extra);
157 border-radius: 3px;
158 }
159 .br-fill.small {
160 background: var(--br-need);
161 }
162 .br-stats2 {
163 display: grid;
164 grid-template-columns: 1fr 1fr;
165 gap: 8px;
166 margin-top: 6px;
167 }
168 .br-right {
169 min-width: 0;
170 }
171 .br-hd {
172 margin-bottom: 6px;
173 font-size: 11.5px;
174 color: var(--br-mut);
175 white-space: nowrap;
176 overflow: hidden;
177 text-overflow: ellipsis;
178 }
179 .br-hd b {
180 color: var(--br-fg);
181 }
182 .br-grid {
183 display: grid;
184 grid-template-columns: repeat(14, minmax(0, 1fr));
185 gap: 3px;
186 }
187 .br-t {
188 aspect-ratio: 1;
189 background: color-mix(in srgb, var(--br-mut) 13%, transparent);
190 border: 1px solid transparent;
191 border-radius: 3px;
192 transition:
193 background 0.45s,
194 border-color 0.45s,
195 opacity 0.45s;
196 }
197 .br-t.need {
198 background: color-mix(in srgb, var(--br-need) 55%, transparent);
199 }
200 .br-t.extra {
201 background: var(--br-extra);
202 }
203 .br-t.pop {
204 animation: brpop 0.45s ease;
205 }
206 @keyframes brpop {
207 from {
208 transform: scale(1.5);
209 filter: brightness(1.5);
210 }
211 }
212 .br-t.gone {
213 background: transparent;
214 border: 1px dashed var(--br-bd2);
215 }
216 .br-foot {
217 display: flex;
218 align-items: center;
219 justify-content: space-between;
220 margin-top: 8px;
221 }
222 .br-legend {
223 font-size: 11.5px;
224 color: var(--br-mut);
225 }
226 .br-legend .br-sw + .br-sw,
227 .br-legend .extra {
228 margin-left: 10px;
229 }
230 .br-foot button {
231 padding: 3px 10px;
232 font-size: 12px;
233 }
234 .br-sw {
235 display: inline-block;
236 width: 10px;
237 height: 10px;
238 margin-right: 6px;
239 vertical-align: -1px;
240 border-radius: 2px;
241 }
242 .br-sw.need {
243 background: color-mix(in srgb, var(--br-need) 55%, transparent);
244 }
245 .br-sw.extra {
246 background: var(--br-extra);
247 }
248 @media (max-width: 620px) {
249 .br-body {
250 grid-template-columns: minmax(0, 1fr);
251 }
252 .br-grid {
253 grid-template-columns: repeat(23, minmax(0, 1fr));
254 gap: 2px;
255 }
256 .br-v {
257 font-size: 17px;
258 }
259 }
260 @media (prefers-reduced-motion: reduce) {
261 .br * {
262 animation: none !important;
263 transition: none !important;
264 }
265 }
266 </style>
267
268 <script>
269 // Measured: error-category.ts cost 3,346 KB heap and 36 ms with the root
270 // import, 9 KB with effect/Effect + effect/Predicate.
271 const ROOT_KB = 3346;
272 const DIRECT_KB = 9;
273 const ROOT_MS = 36;
274
275 // The 138 modules effect 4.0.0 re-exports from dist/index.js, in index order.
276 const ALL =
277 "Arbitrary Array BigDecimal BigInt Boolean Brand ByteSize Cache Cause Channel ChannelSchema Chunk Clock Combiner Config ConfigProvider Console Context Cron Crypto Data DateTime Deferred Differ Duration Effect Effectable Equal Equivalence ErrorReporter ExecutionPlan Exit Fiber FiberHandle FiberMap FiberSet FileSystem Filter Formatter Function Graph Hash HashMap HashRing HashSet HKT Inspectable Iterable JsonPatch JsonPointer JsonSchema Latch Layer LayerMap LayerRef Logger LogLevel ManagedRuntime Match Metric MutableHashMap MutableHashSet MutableList MutableRef Newtype NonEmptyIterable Number Optic Option Order Ordering PartitionedSemaphore Path Pipeable PlatformError Pool Predicate PrimaryKey PubSub Pull Queue Random RcMap RcRef Record Redactable Redacted Reducer Ref References RegExp Request RequestResolver Resource Result Runtime Schedule Scheduler Schema SchemaAST SchemaGetter SchemaIssue SchemaParser SchemaRepresentation SchemaTransformation Scope ScopedCache ScopedRef Semaphore Sink StandardSchema Stdio Stream String Struct SubscriptionRef Symbol SynchronizedRef Take Terminal Tracer Trie Tuple TxChunk TxDeferred TxHashMap TxHashSet TxPriorityQueue TxPubSub TxQueue TxReentrantLock TxRef TxSemaphore TxSubscriptionRef Types UndefinedOr Unify Utils".split(
278 " ",
279 );
280
281 // Reachable from effect/Effect + effect/Predicate.
282 const NEED = new Set(
283 "Array Cause Clock Combiner Context Cron Data Deferred Duration Effect Effectable Equal Equivalence ExecutionPlan Exit Filter Formatter Function Hash Inspectable Iterable Layer Metric Number Option Order Pipeable Predicate Pull Record Redactable Reducer References Request Result Schedule Scheduler Scope String Tracer Tuple Utils".split(
284 " ",
285 ),
286 );
287
288 // The other 96, in Node's evaluation order, with the KB on disk each one
289 // brings in (its file plus internal files first evaluated under it).
290 const EXTRA: [string, number][] = [["Random",15.7],["BigDecimal",70.5],["BigInt",22.7],["ByteSize",15.5],["Chunk",65.9],["DateTime",60.6],["HashMap",53.9],["HashSet",14],["Redacted",24.5],["SchemaIssue",47.4],["SchemaGetter",60],["SchemaTransformation",50.3],["SchemaAST",102.4],["SchemaParser",47.2],["JsonPointer",7.1],["JsonSchema",46],["RegExp",11.4],["JsonPatch",49.6],["Struct",40.7],["Optic",26],["Schema",356],["Arbitrary",135.9],["Boolean",10.2],["Brand",4.5],["MutableHashMap",17.5],["Cache",35.5],["Fiber",11.1],["Latch",6.9],["MutableRef",21.1],["MutableList",16.2],["PubSub",72.2],["Queue",51.8],["Semaphore",11.1],["Take",0.6],["Channel",144.7],["ChannelSchema",4.8],["PlatformError",5.7],["Sink",42.2],["RcMap",16.1],["RcRef",7.7],["Stream",239.2],["FileSystem",12.6],["Path",20.7],["ConfigProvider",33.5],["LogLevel",8.3],["Config",37.7],["Console",23.2],["Crypto",7.3],["Differ",0.3],["ErrorReporter",11.5],["FiberHandle",18.8],["FiberMap",24.2],["FiberSet",15.7],["Graph",215.3],["PrimaryKey",2.5],["HashRing",10.7],["HKT",0],["LayerMap",7.3],["LayerRef",5.7],["Logger",29.4],["ManagedRuntime",5.8],["Match",53.6],["MutableHashSet",9.3],["Newtype",5.4],["NonEmptyIterable",1.5],["Ordering",3],["PartitionedSemaphore",12.7],["Pool",26],["Ref",17.1],["UndefinedOr",66.3],["RequestResolver",87],["SynchronizedRef",16.8],["ScopedRef",5],["Resource",4],["Runtime",9.5],["SchemaRepresentation",137.3],["ScopedCache",21.5],["StandardSchema",0.2],["Stdio",3],["SubscriptionRef",23.7],["Symbol",0.8],["Terminal",2.4],["Trie",31],["TxRef",5.9],["TxChunk",20.4],["TxDeferred",7.3],["TxHashMap",49.3],["TxHashSet",20.7],["TxPriorityQueue",13.7],["TxQueue",37.7],["TxPubSub",19.3],["TxReentrantLock",17],["TxSemaphore",19],["TxSubscriptionRef",12.7],["Types",0.4],["Unify",1.9]];
291 const DISK = EXTRA.reduce((a, [, b]) => a + b, 0);
292
293 const CODE = {
294 root: `<span class="k">import</span> { Effect, Predicate }\n <span class="k">from</span> <span class="s">"effect"</span>`,
295 fixing: `<span class="k">import</span> { Effect, Predicate }\n <span class="k">from</span> <span class="old">"effect"</span>`,
296 direct: `<span class="k">import</span> * as Effect\n <span class="k">from</span> <span class="new">"effect/Effect"</span>\n<span class="k">import</span> * as Predicate\n <span class="k">from</span> <span class="new">"effect/Predicate"</span>`,
297 };
298
299 const root = document.getElementById("br");
300 if (root) {
301 const $ = (id: string) => document.getElementById(`br-${id}`)!;
302 const reduced = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
303 const fmt = (kb: number) => (kb >= 1000 ? `${(kb / 1000).toFixed(1)} MB` : `${Math.round(kb)} KB`);
304
305 $("grid").innerHTML = ALL.map((n) => `<i class="br-t" data-n="${n}" title="${n}"></i>`).join("");
306 const tile = new Map(
307 [...$("grid").children].map((el) => [(el as HTMLElement).dataset.n!, el as HTMLElement]),
308 );
309
310 let run = 0;
311 const wait = (ms: number) => new Promise((r) => setTimeout(r, reduced() ? 0 : ms));
312
313 function meters(kb: number, ms: string, n: number) {
314 $("heap").textContent = fmt(kb);
315 const fill = $("fill");
316 fill.classList.toggle("small", kb < 100);
317 fill.style.setProperty("--pct", `${(100 * kb) / ROOT_KB}%`);
318 fill.style.setProperty("--min", kb < 100 ? "3px" : "0");
319 $("ms").textContent = ms;
320 $("n").textContent = String(n);
321 }
322
323 /** Root import loads everything; then the line is fixed and the extra modules drop out. */
324 async function play() {
325 const me = ++run;
326 $("code").innerHTML = CODE.root;
327 for (const [n, el] of tile) el.className = `br-t${NEED.has(n) ? " need" : ""}`;
328 $("fill").style.transition = "none";
329 let kb = DIRECT_KB;
330 let disk = 0;
331 meters(kb, "0 ms", NEED.size);
332 await wait(30);
333 $("fill").style.transition = "";
334 await wait(500);
335 if (me !== run) return;
336
337 // Fill at a steady rate over a fixed time. Tiles light up as the
338 // bar passes their share of the bytes, so big modules light later.
339 $("fill").style.transition = "none";
340 const DURATION = reduced() ? 0 : 2200;
341 let lit = 0;
342 await new Promise<void>((done) => {
343 const t0 = performance.now();
344 const frame = (now: number) => {
345 if (me !== run) return done();
346 const p = DURATION ? Math.min(1, (now - t0) / DURATION) : 1;
347 const target = p * DISK;
348 while (lit < EXTRA.length && disk + EXTRA[lit]![1] <= target + 1e-9) {
349 const [n, b] = EXTRA[lit]!;
350 disk += b;
351 const el = tile.get(n)!;
352 el.classList.add("extra");
353 if (DURATION) el.classList.add("pop");
354 lit++;
355 }
356 kb = DIRECT_KB + (ROOT_KB - DIRECT_KB) * p;
357 meters(kb, `${Math.round(ROOT_MS * p)} ms`, NEED.size + lit);
358 if (p < 1) requestAnimationFrame(frame);
359 else done();
360 };
361 requestAnimationFrame(frame);
362 });
363 if (me !== run) return;
364 $("fill").style.transition = "";
365 meters(ROOT_KB, `${ROOT_MS} ms`, ALL.length);
366
367 // The fix.
368 await wait(1800);
369 if (me !== run) return;
370 $("code").innerHTML = CODE.fixing;
371 await wait(700);
372 if (me !== run) return;
373 $("code").innerHTML = CODE.direct;
374 await wait(500);
375 if (me !== run) return;
376 for (const [n] of EXTRA) tile.get(n)!.className = "br-t gone";
377 meters(DIRECT_KB, "—", NEED.size);
378 }
379
380 $("replay").onclick = () => void play();
381
382 // Start idle; play once the figure scrolls into view.
383 $("code").innerHTML = CODE.root;
384 meters(0, "0 ms", 0);
385 const io = new IntersectionObserver(
386 (es) => {
387 if (es.some((e) => e.isIntersecting)) {
388 io.disconnect();
389 void play();
390 }
391 },
392 { threshold: 0.4 },
393 );
394 io.observe(root);
395 }
396 </script>