@klinking/colander 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/formats/date.cjs +49 -0
- package/dist/formats/date.d.cts +45 -0
- package/dist/formats/date.d.mts +45 -0
- package/dist/formats/date.mjs +2 -0
- package/dist/formats/object.cjs +49 -0
- package/dist/formats/object.d.cts +45 -0
- package/dist/formats/object.d.mts +45 -0
- package/dist/formats/object.mjs +2 -0
- package/dist/formats/plain-date-time.cjs +49 -0
- package/dist/formats/plain-date-time.d.cts +45 -0
- package/dist/formats/plain-date-time.d.mts +45 -0
- package/dist/formats/plain-date-time.mjs +2 -0
- package/dist/formats/plain-date.cjs +49 -0
- package/dist/formats/plain-date.d.cts +45 -0
- package/dist/formats/plain-date.d.mts +45 -0
- package/dist/formats/plain-date.mjs +2 -0
- package/dist/formats/plain-month-day.cjs +49 -0
- package/dist/formats/plain-month-day.d.cts +45 -0
- package/dist/formats/plain-month-day.d.mts +45 -0
- package/dist/formats/plain-month-day.mjs +2 -0
- package/dist/formats/plain-year-month.cjs +49 -0
- package/dist/formats/plain-year-month.d.cts +45 -0
- package/dist/formats/plain-year-month.d.mts +45 -0
- package/dist/formats/plain-year-month.mjs +2 -0
- package/dist/formats/zoned-date-time.cjs +49 -0
- package/dist/formats/zoned-date-time.d.cts +45 -0
- package/dist/formats/zoned-date-time.d.mts +45 -0
- package/dist/formats/zoned-date-time.mjs +2 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
- package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
- package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
- package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
- package/package.json +89 -0
- package/src/calendar-context.ts +22 -0
- package/src/calendar-provider.test.tsx +123 -0
- package/src/calendar-provider.tsx +538 -0
- package/src/calendar-types.ts +212 -0
- package/src/compute-weeks-in-window.test.ts +83 -0
- package/src/compute-weeks-in-window.ts +40 -0
- package/src/context.ts +34 -0
- package/src/day-cell.tsx +635 -0
- package/src/drag-handle.tsx +137 -0
- package/src/formats/date.ts +110 -0
- package/src/formats/formats.test.ts +18 -0
- package/src/formats/object.ts +110 -0
- package/src/formats/plain-date-time.ts +110 -0
- package/src/formats/plain-date.ts +110 -0
- package/src/formats/plain-month-day.ts +110 -0
- package/src/formats/plain-year-month.ts +110 -0
- package/src/formats/zoned-date-time.ts +110 -0
- package/src/grid-header.tsx +141 -0
- package/src/grid.event-perf.test.tsx +282 -0
- package/src/grid.perf.test.tsx +467 -0
- package/src/grid.tsx +608 -0
- package/src/index.ts +116 -0
- package/src/keyboard.test.ts +498 -0
- package/src/keyboard.ts +142 -0
- package/src/month-separator.test.tsx +183 -0
- package/src/month-separator.tsx +238 -0
- package/src/month-view-context.ts +26 -0
- package/src/month-view-types.ts +89 -0
- package/src/month-view.test.tsx +1433 -0
- package/src/month-view.tsx +373 -0
- package/src/navigation.tsx +350 -0
- package/src/overflow.test.ts +124 -0
- package/src/overflow.ts +233 -0
- package/src/range-preview.tsx +90 -0
- package/src/resolve-first-week.test.ts +132 -0
- package/src/resolve-first-week.ts +145 -0
- package/src/root-selection.ts +621 -0
- package/src/selected-range.tsx +163 -0
- package/src/temporal-polyfill.test.ts +317 -0
- package/src/temporal-polyfill.ts +566 -0
- package/src/test-temporal.ts +17 -0
- package/src/types.ts +814 -0
- package/src/utils.bench.ts +183 -0
- package/src/utils.test.ts +983 -0
- package/src/utils.ts +493 -0
- package/src/view-context.ts +28 -0
- package/src/week-number.tsx +118 -0
- package/src/weeks-grid.tsx +265 -0
- package/src/weeks-keyboard.test.ts +222 -0
- package/src/weeks-keyboard.ts +156 -0
- package/src/weeks-navigation.tsx +209 -0
- package/src/weeks-view-context.ts +26 -0
- package/src/weeks-view-state.ts +421 -0
- package/src/weeks-view-types.ts +102 -0
- package/src/weeks-view.test.tsx +479 -0
- package/src/weeks-view.tsx +127 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { Profiler, type ProfilerOnRenderCallback } from "react";
|
|
4
|
+
// @vitest-environment jsdom
|
|
5
|
+
import { describe, it, expect, beforeAll } from "vitest";
|
|
6
|
+
import { WeekDataContext } from "./context";
|
|
7
|
+
import { Grid, GridBody, GridHeader, GridHeaderCell, DayCellTemplate, DayButton } from "./grid";
|
|
8
|
+
import { MonthView } from "./month-view";
|
|
9
|
+
import { useMonthViewState } from "./month-view-context";
|
|
10
|
+
|
|
11
|
+
type RenderEntry = {
|
|
12
|
+
id: string;
|
|
13
|
+
phase: "mount" | "update" | "nested-update";
|
|
14
|
+
actualDuration: number;
|
|
15
|
+
baseDuration: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function createProfiler() {
|
|
19
|
+
const entries: RenderEntry[] = [];
|
|
20
|
+
const onRender: ProfilerOnRenderCallback = (id, phase, actualDuration, baseDuration) => {
|
|
21
|
+
entries.push({
|
|
22
|
+
id,
|
|
23
|
+
phase: phase as RenderEntry["phase"],
|
|
24
|
+
actualDuration,
|
|
25
|
+
baseDuration,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
return { entries, onRender };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const temporal = {
|
|
32
|
+
Now: Temporal.Now,
|
|
33
|
+
PlainDate: Temporal.PlainDate,
|
|
34
|
+
PlainDateTime: Temporal.PlainDateTime,
|
|
35
|
+
PlainMonthDay: Temporal.PlainMonthDay,
|
|
36
|
+
PlainYearMonth: Temporal.PlainYearMonth,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const defaultProps = {
|
|
40
|
+
temporal,
|
|
41
|
+
locale: "en-US",
|
|
42
|
+
timeZone: "America/New_York",
|
|
43
|
+
format: "PlainDate" as const,
|
|
44
|
+
} as const;
|
|
45
|
+
|
|
46
|
+
const march15 = Temporal.PlainDate.from("2026-03-15");
|
|
47
|
+
const march10 = Temporal.PlainDate.from("2026-03-10");
|
|
48
|
+
const march20 = Temporal.PlainDate.from("2026-03-20");
|
|
49
|
+
|
|
50
|
+
// Generous thresholds — these exist to catch regressions, not enforce tight budgets.
|
|
51
|
+
// Actual durations in dev mode with the Temporal polyfill will be much slower than
|
|
52
|
+
// production. Adjust downward once baseline numbers are established.
|
|
53
|
+
const MOUNT_THRESHOLD_MS = 100;
|
|
54
|
+
const UPDATE_THRESHOLD_MS = 80;
|
|
55
|
+
|
|
56
|
+
describe("Grid render profiling", () => {
|
|
57
|
+
// Warm up the Temporal polyfill so first-run JIT cost doesn't skew mount timings
|
|
58
|
+
beforeAll(() => {
|
|
59
|
+
const { unmount } = render(
|
|
60
|
+
<MonthView {...defaultProps} defaultValue={march15}>
|
|
61
|
+
<Grid />
|
|
62
|
+
</MonthView>,
|
|
63
|
+
);
|
|
64
|
+
unmount();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("initial mount completes within threshold", () => {
|
|
68
|
+
const { entries, onRender } = createProfiler();
|
|
69
|
+
|
|
70
|
+
const { unmount } = render(
|
|
71
|
+
<Profiler id="grid-mount" onRender={onRender}>
|
|
72
|
+
<MonthView {...defaultProps} defaultValue={march15}>
|
|
73
|
+
<Grid />
|
|
74
|
+
</MonthView>
|
|
75
|
+
</Profiler>,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const mount = entries.find((e) => e.phase === "mount");
|
|
79
|
+
expect(mount).toBeDefined();
|
|
80
|
+
expect(mount!.actualDuration).toBeLessThan(MOUNT_THRESHOLD_MS);
|
|
81
|
+
|
|
82
|
+
// Log for visibility in CI
|
|
83
|
+
console.log(
|
|
84
|
+
`[perf] grid mount: actual=${mount!.actualDuration.toFixed(2)}ms base=${mount!.baseDuration.toFixed(2)}ms`,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
unmount();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("re-render on selection change is cheaper than mount", () => {
|
|
91
|
+
const { entries, onRender } = createProfiler();
|
|
92
|
+
let currentValue: Temporal.PlainDate | undefined = march15;
|
|
93
|
+
|
|
94
|
+
const { rerender, unmount } = render(
|
|
95
|
+
<Profiler id="grid-select" onRender={onRender}>
|
|
96
|
+
<MonthView {...defaultProps} value={currentValue}>
|
|
97
|
+
<Grid />
|
|
98
|
+
</MonthView>
|
|
99
|
+
</Profiler>,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const mountDuration = entries.find((e) => e.phase === "mount")?.actualDuration;
|
|
103
|
+
|
|
104
|
+
// Change selection
|
|
105
|
+
currentValue = march20;
|
|
106
|
+
rerender(
|
|
107
|
+
<Profiler id="grid-select" onRender={onRender}>
|
|
108
|
+
<MonthView {...defaultProps} value={currentValue}>
|
|
109
|
+
<Grid />
|
|
110
|
+
</MonthView>
|
|
111
|
+
</Profiler>,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const updates = entries.filter((e) => e.phase === "update");
|
|
115
|
+
expect(updates.length).toBeGreaterThan(0);
|
|
116
|
+
|
|
117
|
+
const updateDuration = updates[updates.length - 1].actualDuration;
|
|
118
|
+
expect(updateDuration).toBeLessThan(UPDATE_THRESHOLD_MS);
|
|
119
|
+
|
|
120
|
+
// Updates should be significantly cheaper than mount (memoization working)
|
|
121
|
+
if (mountDuration) {
|
|
122
|
+
expect(updateDuration).toBeLessThan(mountDuration * 0.7);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
console.log(
|
|
126
|
+
`[perf] selection change: mount=${mountDuration?.toFixed(2)}ms update=${updateDuration.toFixed(2)}ms ratio=${mountDuration ? (updateDuration / mountDuration).toFixed(2) : "N/A"}`,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
unmount();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("month navigation re-render stays within threshold", () => {
|
|
133
|
+
const { entries, onRender } = createProfiler();
|
|
134
|
+
|
|
135
|
+
const { rerender, unmount } = render(
|
|
136
|
+
<Profiler id="grid-nav" onRender={onRender}>
|
|
137
|
+
<MonthView {...defaultProps} defaultValue={march15}>
|
|
138
|
+
<Grid />
|
|
139
|
+
</MonthView>
|
|
140
|
+
</Profiler>,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// Navigate to April by changing value to April 15
|
|
144
|
+
const april15 = Temporal.PlainDate.from("2026-04-15");
|
|
145
|
+
rerender(
|
|
146
|
+
<Profiler id="grid-nav" onRender={onRender}>
|
|
147
|
+
<MonthView {...defaultProps} value={april15}>
|
|
148
|
+
<Grid />
|
|
149
|
+
</MonthView>
|
|
150
|
+
</Profiler>,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const updates = entries.filter((e) => e.phase === "update");
|
|
154
|
+
expect(updates.length).toBeGreaterThan(0);
|
|
155
|
+
|
|
156
|
+
const navDuration = updates[updates.length - 1].actualDuration;
|
|
157
|
+
expect(navDuration).toBeLessThan(UPDATE_THRESHOLD_MS);
|
|
158
|
+
|
|
159
|
+
console.log(`[perf] month navigation: ${navDuration.toFixed(2)}ms`);
|
|
160
|
+
|
|
161
|
+
unmount();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("range selection re-render stays within threshold", () => {
|
|
165
|
+
const { entries, onRender } = createProfiler();
|
|
166
|
+
|
|
167
|
+
const { rerender, unmount } = render(
|
|
168
|
+
<Profiler id="grid-range" onRender={onRender}>
|
|
169
|
+
<MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march15 }}>
|
|
170
|
+
<Grid />
|
|
171
|
+
</MonthView>
|
|
172
|
+
</Profiler>,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
// Expand range
|
|
176
|
+
rerender(
|
|
177
|
+
<Profiler id="grid-range" onRender={onRender}>
|
|
178
|
+
<MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march20 }}>
|
|
179
|
+
<Grid />
|
|
180
|
+
</MonthView>
|
|
181
|
+
</Profiler>,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const updates = entries.filter((e) => e.phase === "update");
|
|
185
|
+
expect(updates.length).toBeGreaterThan(0);
|
|
186
|
+
|
|
187
|
+
const rangeDuration = updates[updates.length - 1].actualDuration;
|
|
188
|
+
expect(rangeDuration).toBeLessThan(UPDATE_THRESHOLD_MS);
|
|
189
|
+
|
|
190
|
+
console.log(`[perf] range expand: ${rangeDuration.toFixed(2)}ms`);
|
|
191
|
+
|
|
192
|
+
unmount();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("rapid state changes (simulated drag) complete without accumulating cost", () => {
|
|
196
|
+
const { entries, onRender } = createProfiler();
|
|
197
|
+
|
|
198
|
+
const days = Array.from({ length: 10 }, (_, i) =>
|
|
199
|
+
Temporal.PlainDate.from(`2026-03-${String(i + 5).padStart(2, "0")}`),
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const { rerender, unmount } = render(
|
|
203
|
+
<Profiler id="grid-drag" onRender={onRender}>
|
|
204
|
+
<MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: days[0] }}>
|
|
205
|
+
<Grid />
|
|
206
|
+
</MonthView>
|
|
207
|
+
</Profiler>,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
// Simulate dragging across 10 days
|
|
211
|
+
for (const day of days.slice(1)) {
|
|
212
|
+
rerender(
|
|
213
|
+
<Profiler id="grid-drag" onRender={onRender}>
|
|
214
|
+
<MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: day }}>
|
|
215
|
+
<Grid />
|
|
216
|
+
</MonthView>
|
|
217
|
+
</Profiler>,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const updates = entries.filter((e) => e.phase === "update");
|
|
222
|
+
const durations = updates.map((e) => e.actualDuration);
|
|
223
|
+
const maxDuration = Math.max(...durations);
|
|
224
|
+
const avgDuration = durations.reduce((a, b) => a + b, 0) / durations.length;
|
|
225
|
+
|
|
226
|
+
// No single update should be wildly expensive
|
|
227
|
+
expect(maxDuration).toBeLessThan(UPDATE_THRESHOLD_MS);
|
|
228
|
+
// Average should stay reasonable
|
|
229
|
+
expect(avgDuration).toBeLessThan(UPDATE_THRESHOLD_MS / 2);
|
|
230
|
+
|
|
231
|
+
console.log(
|
|
232
|
+
`[perf] rapid drag (${durations.length} updates): avg=${avgDuration.toFixed(2)}ms max=${maxDuration.toFixed(2)}ms`,
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
unmount();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("measures per-week-row re-render cost on selection change", () => {
|
|
239
|
+
const weekProfilers = Array.from({ length: 6 }, () => createProfiler());
|
|
240
|
+
|
|
241
|
+
function ProfiledGrid() {
|
|
242
|
+
const { weeks } = useMonthViewState();
|
|
243
|
+
return (
|
|
244
|
+
<>
|
|
245
|
+
<GridHeader>
|
|
246
|
+
<GridHeaderCell />
|
|
247
|
+
</GridHeader>
|
|
248
|
+
<GridBody>
|
|
249
|
+
{weeks.map((weekDays, i) => (
|
|
250
|
+
<Profiler
|
|
251
|
+
key={weekDays[0].toString()}
|
|
252
|
+
id={`week-${i}`}
|
|
253
|
+
onRender={weekProfilers[i].onRender}
|
|
254
|
+
>
|
|
255
|
+
<WeekDataContext.Provider value={{ days: weekDays, weekIndex: i }}>
|
|
256
|
+
<tr>
|
|
257
|
+
<DayCellTemplate>
|
|
258
|
+
<DayButton />
|
|
259
|
+
</DayCellTemplate>
|
|
260
|
+
</tr>
|
|
261
|
+
</WeekDataContext.Provider>
|
|
262
|
+
</Profiler>
|
|
263
|
+
))}
|
|
264
|
+
</GridBody>
|
|
265
|
+
</>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const march16 = Temporal.PlainDate.from("2026-03-16");
|
|
270
|
+
|
|
271
|
+
const { rerender, unmount } = render(
|
|
272
|
+
<MonthView {...defaultProps} value={march15}>
|
|
273
|
+
<Grid>
|
|
274
|
+
<ProfiledGrid />
|
|
275
|
+
</Grid>
|
|
276
|
+
</MonthView>,
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
// Clear mount entries
|
|
280
|
+
for (const p of weekProfilers) p.entries.length = 0;
|
|
281
|
+
|
|
282
|
+
// Change selection within the same week
|
|
283
|
+
rerender(
|
|
284
|
+
<MonthView {...defaultProps} value={march16}>
|
|
285
|
+
<Grid>
|
|
286
|
+
<ProfiledGrid />
|
|
287
|
+
</Grid>
|
|
288
|
+
</MonthView>,
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
const weekUpdateDurations = weekProfilers.map((p) => {
|
|
292
|
+
const updates = p.entries.filter((e) => e.phase === "update");
|
|
293
|
+
return updates.length > 0 ? updates[updates.length - 1].actualDuration : 0;
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const weekSummary = weekUpdateDurations.map((d, i) => `week${i}=${d.toFixed(2)}ms`).join(" ");
|
|
297
|
+
console.log(`[perf] per-week re-render: ${weekSummary}`);
|
|
298
|
+
|
|
299
|
+
const rerenderedWeeks = weekUpdateDurations.filter((d) => d > 0.01).length;
|
|
300
|
+
console.log(`[perf] weeks re-rendered: ${rerenderedWeeks}/${weekUpdateDurations.length}`);
|
|
301
|
+
|
|
302
|
+
for (const d of weekUpdateDurations) {
|
|
303
|
+
expect(d).toBeLessThan(UPDATE_THRESHOLD_MS);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
unmount();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("selection change update is at least 40% cheaper than mount (memoization effect)", () => {
|
|
310
|
+
// This test measures the aggregate effect of context splitting + React.memo
|
|
311
|
+
// at the grid level. In jsdom, per-cell DOM savings are negligible, but
|
|
312
|
+
// the aggregate savings across 42 cells are clearly measurable.
|
|
313
|
+
const { entries, onRender } = createProfiler();
|
|
314
|
+
|
|
315
|
+
const { rerender, unmount } = render(
|
|
316
|
+
<Profiler id="grid-memo" onRender={onRender}>
|
|
317
|
+
<MonthView {...defaultProps} value={march15}>
|
|
318
|
+
<Grid />
|
|
319
|
+
</MonthView>
|
|
320
|
+
</Profiler>,
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
const mountDuration = entries.find((e) => e.phase === "mount")!.actualDuration;
|
|
324
|
+
|
|
325
|
+
const march16 = Temporal.PlainDate.from("2026-03-16");
|
|
326
|
+
rerender(
|
|
327
|
+
<Profiler id="grid-memo" onRender={onRender}>
|
|
328
|
+
<MonthView {...defaultProps} value={march16}>
|
|
329
|
+
<Grid />
|
|
330
|
+
</MonthView>
|
|
331
|
+
</Profiler>,
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
const updates = entries.filter((e) => e.phase === "update");
|
|
335
|
+
const updateDuration = updates[updates.length - 1].actualDuration;
|
|
336
|
+
const ratio = updateDuration / mountDuration;
|
|
337
|
+
|
|
338
|
+
console.log(
|
|
339
|
+
`[perf] memo effect: mount=${mountDuration.toFixed(2)}ms update=${updateDuration.toFixed(2)}ms ratio=${ratio.toFixed(2)}`,
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
// Before context splitting + memo: ratio was ~0.43
|
|
343
|
+
// After multi-month support (GridMonthContext + WeekDataContext in fallback): ratio ≤ 0.45
|
|
344
|
+
expect(ratio).toBeLessThan(0.45);
|
|
345
|
+
|
|
346
|
+
unmount();
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("multi-month mount and update stay within threshold", () => {
|
|
350
|
+
const { entries, onRender } = createProfiler();
|
|
351
|
+
|
|
352
|
+
const { rerender, unmount } = render(
|
|
353
|
+
<Profiler id="grid-multi" onRender={onRender}>
|
|
354
|
+
<MonthView {...defaultProps} value={march15} numberOfMonths={3}>
|
|
355
|
+
<Grid monthIndex={0} />
|
|
356
|
+
<Grid monthIndex={1} />
|
|
357
|
+
<Grid monthIndex={2} />
|
|
358
|
+
</MonthView>
|
|
359
|
+
</Profiler>,
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
const mountDuration = entries.find((e) => e.phase === "mount")!.actualDuration;
|
|
363
|
+
|
|
364
|
+
// 3 grids worth of cells — mount threshold scales linearly
|
|
365
|
+
expect(mountDuration).toBeLessThan(MOUNT_THRESHOLD_MS * 3);
|
|
366
|
+
|
|
367
|
+
const march16 = Temporal.PlainDate.from("2026-03-16");
|
|
368
|
+
rerender(
|
|
369
|
+
<Profiler id="grid-multi" onRender={onRender}>
|
|
370
|
+
<MonthView {...defaultProps} value={march16} numberOfMonths={3}>
|
|
371
|
+
<Grid monthIndex={0} />
|
|
372
|
+
<Grid monthIndex={1} />
|
|
373
|
+
<Grid monthIndex={2} />
|
|
374
|
+
</MonthView>
|
|
375
|
+
</Profiler>,
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
const updates = entries.filter((e) => e.phase === "update");
|
|
379
|
+
const updateDuration = updates[updates.length - 1].actualDuration;
|
|
380
|
+
const ratio = updateDuration / mountDuration;
|
|
381
|
+
|
|
382
|
+
// Memoization should still help even with 3 grids
|
|
383
|
+
expect(ratio).toBeLessThan(0.6);
|
|
384
|
+
|
|
385
|
+
console.log(
|
|
386
|
+
`[perf] multi-month (3): mount=${mountDuration.toFixed(2)}ms update=${updateDuration.toFixed(2)}ms ratio=${ratio.toFixed(2)}`,
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
unmount();
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("hover preview re-render stays within threshold", () => {
|
|
393
|
+
const { entries, onRender } = createProfiler();
|
|
394
|
+
|
|
395
|
+
const { rerender, unmount } = render(
|
|
396
|
+
<Profiler id="grid-preview" onRender={onRender}>
|
|
397
|
+
<MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march20 }}>
|
|
398
|
+
<Grid />
|
|
399
|
+
</MonthView>
|
|
400
|
+
</Profiler>,
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
const mountDuration = entries.find((e) => e.phase === "mount")!.actualDuration;
|
|
404
|
+
|
|
405
|
+
// Approximate hover preview render cost by shifting the range end
|
|
406
|
+
const march22 = Temporal.PlainDate.from("2026-03-22");
|
|
407
|
+
rerender(
|
|
408
|
+
<Profiler id="grid-preview" onRender={onRender}>
|
|
409
|
+
<MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march22 }}>
|
|
410
|
+
<Grid />
|
|
411
|
+
</MonthView>
|
|
412
|
+
</Profiler>,
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
const updates = entries.filter((e) => e.phase === "update");
|
|
416
|
+
expect(updates.length).toBeGreaterThan(0);
|
|
417
|
+
|
|
418
|
+
const previewDuration = updates[updates.length - 1].actualDuration;
|
|
419
|
+
expect(previewDuration).toBeLessThan(UPDATE_THRESHOLD_MS);
|
|
420
|
+
|
|
421
|
+
const ratio = previewDuration / mountDuration;
|
|
422
|
+
expect(ratio).toBeLessThan(0.75);
|
|
423
|
+
|
|
424
|
+
console.log(
|
|
425
|
+
`[perf] hover preview: mount=${mountDuration.toFixed(2)}ms update=${previewDuration.toFixed(2)}ms ratio=${ratio.toFixed(2)}`,
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
unmount();
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("range expand update is cheaper than mount (memoization effect)", () => {
|
|
432
|
+
const { entries, onRender } = createProfiler();
|
|
433
|
+
|
|
434
|
+
const { rerender, unmount } = render(
|
|
435
|
+
<Profiler id="grid-range-memo" onRender={onRender}>
|
|
436
|
+
<MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march15 }}>
|
|
437
|
+
<Grid />
|
|
438
|
+
</MonthView>
|
|
439
|
+
</Profiler>,
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
const mountDuration = entries.find((e) => e.phase === "mount")!.actualDuration;
|
|
443
|
+
|
|
444
|
+
rerender(
|
|
445
|
+
<Profiler id="grid-range-memo" onRender={onRender}>
|
|
446
|
+
<MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march20 }}>
|
|
447
|
+
<Grid />
|
|
448
|
+
</MonthView>
|
|
449
|
+
</Profiler>,
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
const updates = entries.filter((e) => e.phase === "update");
|
|
453
|
+
const updateDuration = updates[updates.length - 1].actualDuration;
|
|
454
|
+
const ratio = updateDuration / mountDuration;
|
|
455
|
+
|
|
456
|
+
console.log(
|
|
457
|
+
`[perf] range memo effect: mount=${mountDuration.toFixed(2)}ms update=${updateDuration.toFixed(2)}ms ratio=${ratio.toFixed(2)}`,
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
// Range updates should benefit from memo — most cells outside the
|
|
461
|
+
// affected range are skipped entirely. Threshold is generous to
|
|
462
|
+
// account for CI/machine variance (observed 0.39–0.70 in practice).
|
|
463
|
+
expect(ratio).toBeLessThan(0.75);
|
|
464
|
+
|
|
465
|
+
unmount();
|
|
466
|
+
});
|
|
467
|
+
});
|