Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(waterfall): bound tick generation at large timestamp offsets

杨嘉伟adc21b76bcb9
diff --git a/archify/renderers/waterfall/render-waterfall.mjs b/archify/renderers/waterfall/render-waterfall.mjs
index e6db3728..da74ef82 100644
--- a/archify/renderers/waterfall/render-waterfall.mjs
+++ b/archify/renderers/waterfall/render-waterfall.mjs
@@ -171,7 +171,14 @@ const tickStep = (() => {
}
})();
const ticks = [];
-for (let t = Math.ceil(t0 / tickStep) * tickStep; t <= t1 + 1e-9; t += tickStep) ticks.push({ t, x: xOf(t) });
+const firstTick = Math.ceil(t0 / tickStep) * tickStep;
+const tickCount = Math.max(0, Math.floor((t1 - firstTick) / tickStep + 1e-9) + 1);
+for (let index = 0; index < tickCount; index += 1) {
+ const t = firstTick + index * tickStep;
+ // Large timestamps can round adjacent ticks to the same double. Index-based
+ // iteration remains bounded even when adding tickStep cannot advance t.
+ if (ticks.at(-1)?.t !== t) ticks.push({ t, x: xOf(t) });
+}
const LABEL_GAP = 7;
const parentIds = new Set(rows.map((row) => row.parent).filter((id) => id !== undefined));
diff --git a/test/waterfall-rendering.test.mjs b/test/waterfall-rendering.test.mjs
index efe988e0..ea302e9f 100644
--- a/test/waterfall-rendering.test.mjs
+++ b/test/waterfall-rendering.test.mjs
@@ -19,7 +19,7 @@ function run(diagram, extra = []) {
const input = path.join(directory, 'candidate.waterfall.json');
const output = path.join(directory, 'candidate.html');
fs.writeFileSync(input, JSON.stringify(diagram));
- return { ...spawnSync(process.execPath, [renderer, input, output, ...extra], { cwd: directory, encoding: 'utf8' }), output };
+ return { ...spawnSync(process.execPath, [renderer, input, output, ...extra], { cwd: directory, encoding: 'utf8', timeout: 10000 }), output };
}
function layoutOf(diagram) {
const result = run(diagram, ['--layout-json']);
@@ -58,6 +58,19 @@ test('waterfall: bar geometry is exactly the recorded timing on one axis', () =>
assert.deepEqual(report.rows.map((row) => row.id), ['request', 'auth', 'inventory', 'discount', 'payment', 'save']);
});
+test('waterfall: large timestamps terminate when tick increments are below floating-point resolution', () => {
+ const diagram = clone(small);
+ diagram.spans = [{ id: 'request', name: 'Request', start: 1e16, end: 1e16 + 2 }];
+ const result = run(diagram, ['--layout-json']);
+ assert.equal(result.status, 0, result.stderr || result.error?.message);
+ const report = JSON.parse(result.stdout);
+ assert.equal(report.wall, 2);
+ assert.equal(report.rows[0].label, '2 ms');
+ assert.ok(Number.isFinite(report.rows[0].x0));
+ assert.ok(Number.isFinite(report.rows[0].x1));
+ assert.ok(report.rows[0].x1 > report.rows[0].x0);
+});
+
test('waterfall: percentages name their denominator and are never summed into the parent', () => {
const html = fs.readFileSync(run(small).output, 'utf8');
assert.match(html, /data-node-id="payment"[^>]*aria-label="[^"]*400–1,050 ms · 650 ms · 54% of 1,200 ms wall-clock/);