Files
superGeometry 1d40bd0daf The view's drawing buffer isn't kept; a list that isn't one is a damaged step
- The 3D view no longer keeps its drawing buffer between frames (the browser
  shows each frame the quick way, which matters on phones). The library's
  picture and the screenshot draw the view right before they read it, as
  they already did.
- A step whose tools, bodies, edges or faces aren't a list (a damaged file)
  is refused as damaged before it runs, instead of tripping the code and
  being put into words afterwards (with the raw error in the console).
- The perf test checks memory only when it can collect garbage first (run
  with --expose-gc, as its first line says); without it, it failed on
  garbage not yet collected.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-10 19:54:58 +02:00

30 lines
2.3 KiB
TypeScript

// Run: node --expose-gc --import tsx tests/perf.test.ts (or npx tsx) - rebuild memory and speed on a long project.
import opencascade from "replicad-opencascadejs";
import { setOC } from "replicad";
import { regenerate } from "../src/kernel/engine";
import { arrangement, regionRef } from "../src/sketch/regions";
setOC(await (opencascade as unknown as () => Promise<any>)());
// A sketch with 20 000 points of spline (≈1.5 MB of JSON) first, then 120 small steps.
const big = { id: "big", name: "Sketch", type: "sketch", plane: { origin: [0, 0, 0], xDir: [1, 0, 0], normal: [0, 0, 1] }, entities: [{ id: "sp", kind: "spline", closed: false, mode: "fit", points: Array.from({ length: 20000 }, (_, i) => [i * 0.001 + 100, Math.sin(i) * 0.001 + 100]) }] };
const es = [{ id: "r", kind: "rect", center: [0, 0], w: 40, h: 30, rotation: 0 }];
const fs: any[] = [big, { id: "sk", name: "S", type: "sketch", plane: big.plane, entities: es }, { id: "b", name: "E", type: "extrude", source: { kind: "profile", sketch: "sk", regions: arrangement(es as any).regions.map(regionRef) }, distance: 20, mode: "new" }];
for (let i = 0; i < 120; i++) fs.push({ id: `t${i}`, name: "T", type: "transform", bodies: ["b"], copy: false, op: { kind: "move", translate: [0.01, 0, 0] } });
(globalThis as any).gc?.();
const m0 = process.memoryUsage().heapUsed;
const t0 = performance.now();
await regenerate(fs);
const t1 = performance.now();
fs[fs.length - 1] = { ...fs[fs.length - 1], op: { kind: "move", translate: [0.02, 0, 0] } };
await regenerate(fs);
const t2 = performance.now();
global.gc?.();
const grew = (process.memoryUsage().heapUsed - m0) / 1e6;
// (Memory is only told after a collection: run without --expose-gc, what is
// measured is mostly garbage not yet collected - the speed is still checked.)
const collected = typeof (globalThis as any).gc === "function";
if (!collected) console.log(" (run with node --expose-gc --import tsx for the memory check)");
const ok = (!collected || grew < 25) && t2 - t1 < 500;
console.log(ok ? "ok " : "FAIL", "long project with a big sketch first: rebuild cache stays small and quick");
console.log(`heap +${((process.memoryUsage().heapUsed - m0) / 1e6).toFixed(0)} MB; full rebuild ${(t1 - t0).toFixed(0)} ms; last step changed ${(t2 - t1).toFixed(0)} ms`);
process.exit(ok ? 0 : 1);