@marver-design/marver 0.29.0 → 0.30.1
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/CHANGELOG.md +60 -0
- package/README.md +2 -1
- package/dist/{anchor-check-DhlpKl2K.mjs → anchor-check-Bv4o-R2T.mjs} +1 -1
- package/dist/{build-CWbrb2bl.mjs → build-zWGXSzly.mjs} +5 -4
- package/dist/cli.mjs +5 -5
- package/dist/{daemon-Sc_z8gT6.mjs → daemon-CChgWJNq.mjs} +2 -2
- package/dist/{dev-DWBKQhxf.mjs → dev-DOgIITpT.mjs} +8 -8
- package/dist/{perf-Denssrko.mjs → perf-6MOTHxay.mjs} +710 -99
- package/dist/perf-BCxAo0IS.mjs +1743 -0
- package/dist/{plugin-DqoZB-D6.mjs → plugin-CFWBcAba.mjs} +928 -539
- package/dist/{poster-CrsjqhY4.mjs → poster-DPPpQiva.mjs} +1 -1
- package/dist/{publish-bakes-DW-NDgU2.mjs → publish-bakes-_Zx8crP3.mjs} +2 -2
- package/dist/{recover-GtJ9UDAB.mjs → recover-mDUVsnPd.mjs} +1 -1
- package/dist/{shot-T04Ixrvq.mjs → shot-d4h_hJi9.mjs} +3 -3
- package/docs/app.md +194 -0
- package/docs/performance.md +100 -19
- package/package.json +1 -1
- package/src/client/frame-host/bridge.js +17 -8
- package/src/client/frame-host/inplace.ts +124 -0
- package/src/client/frame-host/inspect.d.ts +1 -0
- package/src/client/frame-host/inspect.js +13 -4
- package/src/client/frame-host/main.tsx +12 -3
- package/src/client/frame-host/messages.ts +85 -0
- package/src/client/frame-host/signals.d.ts +15 -0
- package/src/client/frame-host/signals.js +219 -0
- package/src/client/recorder-level.ts +41 -0
- package/src/client/shell/App.tsx +158 -88
- package/src/client/shell/BoardList.tsx +103 -48
- package/src/client/shell/Comments.tsx +66 -42
- package/src/client/shell/ContextMenu.tsx +3 -2
- package/src/client/shell/JamSurface.tsx +116 -71
- package/src/client/shell/LockedApp.tsx +19 -3
- package/src/client/shell/Play.tsx +94 -58
- package/src/client/shell/StatusPicker.tsx +19 -9
- package/src/client/shell/Toolbar.tsx +15 -7
- package/src/client/shell/api.ts +18 -4
- package/src/client/shell/app-bridge.ts +12 -6
- package/src/client/shell/app-perf.ts +31 -1
- package/src/client/shell/canvas/Canvas.tsx +17 -6
- package/src/client/shell/canvas/FrameNode.tsx +25 -12
- package/src/client/shell/canvas/Sticky.tsx +4 -2
- package/src/client/shell/canvas/ctl.ts +2 -0
- package/src/client/shell/canvas/ready-watch.ts +4 -0
- package/src/client/shell/canvas/sleep.ts +2 -0
- package/src/client/shell/canvas/updates.ts +13 -6
- package/src/client/shell/commands.ts +765 -0
- package/src/client/shell/comments-store.ts +42 -27
- package/src/client/shell/goto.ts +11 -6
- package/src/client/shell/jam-keys.ts +141 -75
- package/src/client/shell/jam-lane.tsx +19 -12
- package/src/client/shell/jam-panel.tsx +61 -48
- package/src/client/shell/jam-session.tsx +41 -37
- package/src/client/shell/jam-state.ts +9 -1
- package/src/client/shell/jam-surface-parts.tsx +8 -6
- package/src/client/shell/jam-ui.tsx +9 -6
- package/src/client/shell/jam-voice.ts +4 -2
- package/src/client/shell/main.tsx +7 -1
- package/src/client/shell/marks-ui.tsx +11 -0
- package/src/client/shell/perf.ts +51 -5
- package/src/client/shell/recorder-core.ts +4 -1
- package/src/client/shell/recorder-hmr.ts +36 -0
- package/src/client/shell/recorder-reloads.ts +264 -0
- package/src/client/shell/recorder-seams.ts +116 -0
- package/src/client/shell/recorder-self.ts +73 -0
- package/src/client/shell/recorder-signals-core.ts +139 -0
- package/src/client/shell/recorder-signals.ts +485 -0
- package/src/client/shell/recorder.ts +118 -43
- package/src/client/shell/store.ts +112 -32
- package/src/client/shell/whiteout-probes.ts +3 -1
- package/src/client/stage/main.tsx +10 -5
- package/src/shared/app-api.ts +28 -6
- package/src/shared/app-perf.ts +99 -6
- package/src/shared/app-report.ts +586 -0
- package/src/shared/perf-records.ts +445 -0
- package/src/shared/perf-run.ts +6 -2
- package/dist/perf-jam-CLkERSHo.mjs +0 -642
|
@@ -12,19 +12,28 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { api, isStopped } from './api.ts'
|
|
14
14
|
import { CONFIG, PUBLISHED, geometryCause, knownHeight, recorderHooks, reflowIdle, settleRule, useStore, type LoadCause, type Manifest, type MeasureResult, type Node, type RequestCut } from './store.ts'
|
|
15
|
+
import type { BoardWriter, LoadTrigger } from '../../shared/perf-records.ts'
|
|
15
16
|
import { admissionIdle, onAdmissionIdle } from './canvas/admission.ts'
|
|
16
17
|
import { canvasCtl } from './canvas/ctl.ts'
|
|
17
18
|
import { bootOf, iframeOf } from './canvas/frame-registry.ts'
|
|
18
|
-
import { adopt, bound, fitWithin, KEEPALIVE_BYTES, LOAD_MAX_MS, newId, Outbox, outcomeOf, QUIET_MS, SEND_MS, stackLines, type Kind, type Outcome, type PerfRecord, type Track } from './recorder-core.ts'
|
|
19
|
+
import { adopt, bound, bytesOf, fitWithin, KEEPALIVE_BYTES, LOAD_MAX_MS, newId, Outbox, outcomeOf, QUIET_MS, SEND_MS, stackLines, type Kind, type Outcome, type PerfRecord, type Track } from './recorder-core.ts'
|
|
19
20
|
import { PERF_RUN, type PerfRunStatus } from './perf-run.ts'
|
|
20
21
|
import { displayHz } from './app-perf.ts'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
import { nextSeq, PAGE_ID, perfSeams, type LoadPhase } from './recorder-seams.ts'
|
|
23
|
+
import type { DropReason, GestureFields } from '../../shared/perf-records.ts'
|
|
24
|
+
import { fullRecorder } from '../recorder-level.ts'
|
|
25
|
+
import { startReloads } from './recorder-reloads.ts'
|
|
26
|
+
import { errorCounted, modesOn, signalSink, startSignals, type SignalError } from './recorder-signals.ts'
|
|
27
|
+
import { currentCmd, startCommands } from './commands.ts'
|
|
28
|
+
import { selfCounts, startSelf } from './recorder-self.ts'
|
|
29
|
+
|
|
30
|
+
/** This document, in every record (and, in the app, in its hello: the app's records about this tab carry it). Minted in
|
|
31
|
+
* recorder-seams.ts, which the spec 30 streams read without importing this module. */
|
|
32
|
+
export { PAGE_ID }
|
|
24
33
|
|
|
25
34
|
type State = ReturnType<typeof useStore.getState>
|
|
26
35
|
type View = { x: number; y: number; w: number; h: number }
|
|
27
|
-
type Gesture = { type: 'pan' | 'zoom' | 'layout'; ms: number; frames: number; p50: number; p95: number; max: number; over17ms: number; over33ms: number; longFrames: number }
|
|
36
|
+
type Gesture = { type: 'pan' | 'zoom' | 'layout'; ms: number; frames: number; p50: number; p95: number; max: number; over17ms: number; over33ms: number; longFrames: number } & Pick<GestureFields, 'scale' | 'loaf' | 'by'>
|
|
28
37
|
|
|
29
38
|
interface Load {
|
|
30
39
|
id: string; board: string; cause: LoadCause; t0: number
|
|
@@ -36,6 +45,8 @@ interface Load {
|
|
|
36
45
|
quietSent: boolean
|
|
37
46
|
/** the visible cohort: the nodes the first camera placement after the commit showed */
|
|
38
47
|
cohort?: Set<string>
|
|
48
|
+
/** spec 30 #49: its cohort's frames all reached their outcome - `board-open`'s `visibleReady` step, said once */
|
|
49
|
+
visibleReady?: true
|
|
39
50
|
/** store changes that moved a node (before drags are merged), their distance, by cause */
|
|
40
51
|
moves: number; distance: number; causes: Record<string, number>
|
|
41
52
|
errors: number; errAt: Map<string, number>
|
|
@@ -49,7 +60,6 @@ interface Load {
|
|
|
49
60
|
|
|
50
61
|
let on = false
|
|
51
62
|
let ws = ''
|
|
52
|
-
let seq = 0
|
|
53
63
|
let capturesPending = (): boolean => false
|
|
54
64
|
let sealCaptures = (): void => {}
|
|
55
65
|
/** requested, not committed (or cut) yet */
|
|
@@ -85,15 +95,19 @@ let sleeping = (): number => 0
|
|
|
85
95
|
const unowned = { errors: 0, errAt: new Map<string, number>() }
|
|
86
96
|
|
|
87
97
|
const env = (kind: Kind, load: string, body: Record<string, unknown>): PerfRecord =>
|
|
88
|
-
({ ...Object.fromEntries(Object.entries(body).filter(([, x]) => x !== undefined)), v: 1, ws, page: PAGE_ID, load, seq:
|
|
98
|
+
({ ...Object.fromEntries(Object.entries(body).filter(([, x]) => x !== undefined)), v: 1, ws, page: PAGE_ID, load, seq: nextSeq(), ts: Date.now(), kind })
|
|
89
99
|
function rec(kind: Kind, load: string, body: Record<string, unknown>): PerfRecord {
|
|
100
|
+
const t0 = selfCounts.on ? performance.now() : 0 // spec 30 #58: the page's `self`
|
|
90
101
|
if (kind !== 'move') open.clear() // a merged drag ends at the next record of another kind
|
|
91
102
|
const r = env(kind, load, body)
|
|
92
103
|
outbox.push(r)
|
|
93
104
|
armSend()
|
|
105
|
+
if (selfCounts.on) selfCounts.record(performance.now() - t0)
|
|
94
106
|
return r
|
|
95
107
|
}
|
|
96
108
|
const ownerId = () => owner?.id ?? '-'
|
|
109
|
+
/** A load's phase, to whoever listens (spec 30: recorder-seams.ts `load`). */
|
|
110
|
+
const phase = (p: LoadPhase) => perfSeams.load.emit(p)
|
|
97
111
|
/** ms from the load's request; undefined for a moment before it (a document kept from an earlier load) */
|
|
98
112
|
const rel = (L: Load, at?: number) => (at === undefined || at < L.t0 ? undefined : Math.round(at - L.t0))
|
|
99
113
|
const node = (key: string) => useStore.getState().nodes.find((n) => n.key === key)
|
|
@@ -117,10 +131,11 @@ export function startRecorder(opts: { capturesPending: () => boolean; sealCaptur
|
|
|
117
131
|
if (on || PUBLISHED || !CONFIG.workspace || w.__mvRecorderOn) return // a hot-replaced module never records twice
|
|
118
132
|
w.__mvRecorderOn = true
|
|
119
133
|
on = true
|
|
134
|
+
perfSeams.on = true
|
|
120
135
|
ws = CONFIG.workspace
|
|
121
136
|
capturesPending = opts.capturesPending
|
|
122
137
|
sealCaptures = opts.sealCaptures
|
|
123
|
-
recorderHooks.request = (board, cause) => { try { return request(board, cause) } catch { return '' } }
|
|
138
|
+
recorderHooks.request = (board, cause, trigger, writer) => { try { return request(board, cause, trigger, writer) } catch { return '' } }
|
|
124
139
|
recorderHooks.handover = guard(handover)
|
|
125
140
|
recorderHooks.commit = guard(commit)
|
|
126
141
|
recorderHooks.cut = guard(cutRequest)
|
|
@@ -138,6 +153,10 @@ export function startRecorder(opts: { capturesPending: () => boolean; sealCaptur
|
|
|
138
153
|
}))
|
|
139
154
|
addEventListener('pagehide', guard(leave))
|
|
140
155
|
if (import.meta.env.DEV) (window as unknown as { __mvRecorder: unknown }).__mvRecorder = { page: PAGE_ID, ws, state, send }
|
|
156
|
+
// spec 30: the streams write through the page's envelope and outbox, and start only at the full level (#57, #58)
|
|
157
|
+
perfSeams.record = (kind, body, load) => { if (on) rec(kind, load ?? ownerId(), body) }
|
|
158
|
+
if (!fullRecorder()) return
|
|
159
|
+
for (const start of [startReloads, startSignals, startCommands, startSelf]) { try { start() } catch { /* one stream's start never stops another's, nor the page */ } }
|
|
141
160
|
}
|
|
142
161
|
|
|
143
162
|
/** What only the canvas knows, from Canvas.tsx when it mounts: when the camera or a layout animation starts and stops
|
|
@@ -150,13 +169,16 @@ export function attachCanvas(c: { onMotion: (fn: (m: { camera: boolean; preset:
|
|
|
150
169
|
|
|
151
170
|
// ---- loads ------------------------------------------------------------------------------------------------------
|
|
152
171
|
|
|
153
|
-
function request(board: string, cause: LoadCause): string {
|
|
172
|
+
function request(board: string, cause: LoadCause, trigger?: LoadTrigger, writer?: BoardWriter): string {
|
|
154
173
|
if (!on) return ''
|
|
155
174
|
const t0 = performance.now()
|
|
156
175
|
const L: Load = { id: newId(), board, cause, t0, lastMoveAt: t0, quietSent: false, moves: 0, distance: 0, causes: {}, errors: 0, errAt: new Map(), reported: new Map() }
|
|
157
176
|
pending.set(L.id, L)
|
|
158
177
|
// `load`, its uncommitted `cut` and its `commit` carry the request's own id (the load's, once it commits)
|
|
159
|
-
|
|
178
|
+
// spec 30 (#17, #18, `by`): why it read the board, who may have written it, the command behind it
|
|
179
|
+
const why = fullRecorder() ? { trigger, ...writer, by: currentCmd() } : {}
|
|
180
|
+
rec('load', L.id, { board, cause, request: L.id, ...(cause === 'boot' ? { sinceNav: Math.round(t0) } : {}), ...why })
|
|
181
|
+
phase({ phase: 'request', load: L.id, board, cause, ...(fullRecorder() ? { trigger } : {}) })
|
|
160
182
|
// the deadline runs from the request: a load not settled 120 s after it was asked for is cut, committed or not - a
|
|
161
183
|
// board fetch that never answers included
|
|
162
184
|
L.timeout = setTimeout(guard(() => expire(L)), LOAD_MAX_MS)
|
|
@@ -180,6 +202,7 @@ function cutRequest(id: string, reason: RequestCut | 'timeout' | 'hidden'): void
|
|
|
180
202
|
L.done = 'cut'
|
|
181
203
|
L.cutReason = reason
|
|
182
204
|
rec('cut', id, { reason, request: id, ms: Math.round(performance.now() - L.t0) })
|
|
205
|
+
phase({ phase: 'cut', load: id, reason, request: true })
|
|
183
206
|
// its fetch may still answer and mount it
|
|
184
207
|
if (reason === 'timeout' || reason === 'hidden') {
|
|
185
208
|
lapsed.set(id, L)
|
|
@@ -197,7 +220,8 @@ function handover(id: string): void {
|
|
|
197
220
|
if (L && owner && owner !== L && !owner.done) cut(owner, owner.board === L.board ? 'reload' : 'switch')
|
|
198
221
|
}
|
|
199
222
|
|
|
200
|
-
|
|
223
|
+
/** `kept`: the board read again, the nodes whose document stands - any other starts its record over, whatever it held */
|
|
224
|
+
function commit(id: string, nodes: readonly Node[], manifest: Manifest, kept?: ReadonlySet<string>): void {
|
|
201
225
|
const L = pending.get(id) ?? lapsed.get(id)
|
|
202
226
|
if (!L) return
|
|
203
227
|
const late = !pending.has(id)
|
|
@@ -209,10 +233,11 @@ function commit(id: string, nodes: readonly Node[], manifest: Manifest): void {
|
|
|
209
233
|
// mounting is never a move: the baseline is the nodes about to mount
|
|
210
234
|
baseline = new Map(nodes.map((n) => [n.key, { x: n.x, y: n.y, w: n.w, h: n.h }]))
|
|
211
235
|
const keys = new Set(nodes.map((n) => n.key))
|
|
212
|
-
for (const k of [...tracks.keys()]) if (!keys.has(k)) tracks.delete(k)
|
|
236
|
+
for (const k of [...tracks.keys()]) if (!(kept ?? keys).has(k)) tracks.delete(k)
|
|
213
237
|
// a request already cut (its deadline passed, the page hid) mounts all the same: said, its cut kept - its board's
|
|
214
238
|
// geometry is its own from here, every move late
|
|
215
239
|
rec('commit', id, { request: id, ms: Math.round(L.committedAt - L.t0), ...facts(nodes, manifest), ...(late ? { late: true } : {}) })
|
|
240
|
+
phase({ phase: 'commit', load: id, ...(late ? { late: true as const } : {}) })
|
|
216
241
|
if (late) return
|
|
217
242
|
L.quietTimer = setTimeout(guard(() => quiet(L)), QUIET_MS)
|
|
218
243
|
// a page hidden already: cut once the set that mounts this load has run - its nodes, not the board it replaces
|
|
@@ -297,10 +322,18 @@ function progress(n: Node): void {
|
|
|
297
322
|
if (L && !L.done && L.committedAt !== undefined) {
|
|
298
323
|
const o = outcomeNow(n, useStore.getState().manifest)
|
|
299
324
|
if (o && L.reported.get(n.key) !== said(n, o)) frameRecord(L, n, o)
|
|
325
|
+
visibleReadyNow(L)
|
|
300
326
|
}
|
|
301
327
|
settleSoon()
|
|
302
328
|
}
|
|
303
329
|
|
|
330
|
+
/** Spec 30 #49: the cohort's frames all reached their outcome - `board-open`'s `visibleReady` step - once per load. */
|
|
331
|
+
function visibleReadyNow(L: Load): void {
|
|
332
|
+
if (L.visibleReady || !L.cohort || [...L.cohort].some((k) => !L.reported.has(k))) return
|
|
333
|
+
L.visibleReady = true
|
|
334
|
+
phase({ phase: 'visible-ready', load: L.id })
|
|
335
|
+
}
|
|
336
|
+
|
|
304
337
|
function frameRecord(L: Load, n: Node, outcome: Outcome | 'cut'): void {
|
|
305
338
|
const t = tracks.get(n.key)
|
|
306
339
|
const times = [t?.admittedAt, t?.readyAt, t?.firstMeasureAt, t?.settled?.at]
|
|
@@ -347,18 +380,16 @@ function trySettle(): void {
|
|
|
347
380
|
function settle(L: Load, s: State, outs: Outcome[]): void {
|
|
348
381
|
ensureVisible(L)
|
|
349
382
|
s.nodes.forEach((n, i) => { if (L.reported.get(n.key) !== said(n, outs[i])) frameRecord(L, n, outs[i]) })
|
|
350
|
-
const lastReady = (ns: readonly Node[]) => {
|
|
351
|
-
const xs = ns.map((n) => tracks.get(n.key)?.readyAt).filter((x): x is number => x !== undefined)
|
|
352
|
-
return xs.length ? Math.max(0, Math.round(Math.max(...xs) - L.t0)) : undefined
|
|
353
|
-
}
|
|
354
383
|
if (!L.quietSent) { L.quietSent = true; rec('quiet', L.id, { ms: Math.round(L.lastMoveAt - L.t0) }) }
|
|
384
|
+
visibleReadyNow(L)
|
|
355
385
|
rec('settled', L.id, {
|
|
356
386
|
ms: Math.round(performance.now() - L.t0), moves: L.moves, distance: Math.round(L.distance), causes: L.causes, lastMove: rel(L, L.movedAt),
|
|
357
|
-
visibleReadyMs: lastReady(s.nodes.filter((n) => L.cohort?.has(n.key))), allReadyMs: lastReady(s.nodes),
|
|
387
|
+
visibleReadyMs: lastReady(L, s.nodes.filter((n) => L.cohort?.has(n.key))), allReadyMs: lastReady(L, s.nodes),
|
|
358
388
|
missing: outs.filter((o) => o === 'missing').length, neverReady: outs.filter((o) => o === 'never-ready').length, errors: outs.filter((o) => o === 'error').length,
|
|
359
389
|
weight: weight(),
|
|
360
390
|
})
|
|
361
391
|
finish(L, 'settled')
|
|
392
|
+
phase({ phase: 'settled', load: L.id })
|
|
362
393
|
}
|
|
363
394
|
|
|
364
395
|
/** The load ended before it settled: another board, a reload of this one, the page hidden, or 120 s. What its nodes
|
|
@@ -369,15 +400,29 @@ function cut(L: Load, reason: 'switch' | 'reload' | 'hidden' | 'timeout'): void
|
|
|
369
400
|
const s = useStore.getState()
|
|
370
401
|
ensureVisible(L)
|
|
371
402
|
let ready = 0
|
|
403
|
+
const readyNodes: Node[] = []
|
|
372
404
|
for (const n of s.nodes) {
|
|
373
405
|
const o = outcomeNow(n, s.manifest)
|
|
374
|
-
if (o === 'settled' || o === 'ready') ready
|
|
406
|
+
if (o === 'settled' || o === 'ready') { ready++; readyNodes.push(n) }
|
|
375
407
|
if (!o) frameRecord(L, n, 'cut')
|
|
376
408
|
else if (L.reported.get(n.key) !== said(n, o)) frameRecord(L, n, o)
|
|
377
409
|
}
|
|
378
|
-
rec('cut', L.id, { reason, ms: Math.round(performance.now() - L.t0), lastMove: rel(L, L.movedAt), frames: s.nodes.length, ready })
|
|
410
|
+
rec('cut', L.id, { reason, ms: Math.round(performance.now() - L.t0), lastMove: rel(L, L.movedAt), frames: s.nodes.length, ready, ...(fullRecorder() ? partialTimes(L, readyNodes) : {}) })
|
|
379
411
|
L.cutReason = reason
|
|
380
412
|
finish(L, 'cut')
|
|
413
|
+
phase({ phase: 'cut', load: L.id, reason })
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** Spec 30 #19: what a cut load had ready, as `settled` computes it, over the frames ready by then - `visibleReady` says
|
|
417
|
+
* how many of the cohort that is, so a partial time is never read as the whole. */
|
|
418
|
+
function partialTimes(L: Load, ready: readonly Node[]) {
|
|
419
|
+
const visible = ready.filter((n) => L.cohort?.has(n.key))
|
|
420
|
+
return { visibleReadyMs: lastReady(L, visible), allReadyMs: lastReady(L, ready), visibleReady: visible.length }
|
|
421
|
+
}
|
|
422
|
+
/** ms from the request to the last of these nodes' ready; none while none was. */
|
|
423
|
+
function lastReady(L: Load, ns: readonly Node[]): number | undefined {
|
|
424
|
+
const xs = ns.map((n) => tracks.get(n.key)?.readyAt).filter((x): x is number => x !== undefined)
|
|
425
|
+
return xs.length ? Math.max(0, Math.round(Math.max(...xs) - L.t0)) : undefined
|
|
381
426
|
}
|
|
382
427
|
|
|
383
428
|
function finish(L: Load, how: 'settled' | 'cut'): void {
|
|
@@ -407,47 +452,62 @@ function ensureVisible(L: Load): void {
|
|
|
407
452
|
const v = canvasCtl.view()
|
|
408
453
|
L.cohort = v ? cohortIn(v) : new Set()
|
|
409
454
|
rec('visible', L.id, { nodes: L.cohort.size, ms: Math.round(performance.now() - L.t0), assumed: true })
|
|
455
|
+
phase({ phase: 'visible', load: L.id, nodes: L.cohort.size, assumed: true })
|
|
410
456
|
}
|
|
411
457
|
|
|
412
458
|
// ---- errors -----------------------------------------------------------------------------------------------------
|
|
413
459
|
|
|
414
460
|
let inError = false
|
|
415
|
-
/**
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
461
|
+
/** each reason's `dropped` record while it waits to be sent (the next one adds to it): the errors past a load's 50, and
|
|
462
|
+
* what a source's rate or a frame's budget refused (spec 30 #33) */
|
|
463
|
+
const drops = new Map<DropReason, PerfRecord>()
|
|
464
|
+
function drop(reason: DropReason, n: number): void {
|
|
465
|
+
const d = drops.get(reason)
|
|
466
|
+
if (d && d.load === ownerId() && outbox.has(d)) { d.n = (d.n as number) + n; outbox.touch(d) }
|
|
467
|
+
else drops.set(reason, rec('dropped', ownerId(), { n, reason }))
|
|
468
|
+
}
|
|
469
|
+
/** Every source (spec 30 #27-#33): ≤ 50 per load (those past it counted), the same one at most once a second; messages and
|
|
470
|
+
* stack lines cut to 200 characters; the modes on with it. An error after the load settled or was cut is `late` - the
|
|
471
|
+
* load owns the geometry for as long as its board stays open. At the `core` level, what 0.29 did. */
|
|
472
|
+
function logError(e: SignalError): void {
|
|
421
473
|
if (inError) return
|
|
422
474
|
inError = true
|
|
423
475
|
try {
|
|
424
476
|
const message = bound(typeof e.message === 'string' ? e.message : String(e.message ?? ''))
|
|
425
477
|
if (!message) return
|
|
426
478
|
const L = owner, mine = L ?? unowned
|
|
479
|
+
const full = fullRecorder()
|
|
427
480
|
const key = `${e.source}|${e.frame ?? ''}|${message}`, now = performance.now()
|
|
428
|
-
if (now - (mine.errAt.get(key) ?? -Infinity) < 1000) return
|
|
429
|
-
if (mine.errors >= 50) {
|
|
430
|
-
if (over && over.load === ownerId() && outbox.has(over)) { over.n = (over.n as number) + 1; outbox.touch(over) }
|
|
431
|
-
else over = rec('dropped', ownerId(), { n: 1, reason: 'errors' })
|
|
432
|
-
return
|
|
433
|
-
}
|
|
481
|
+
if (now - (mine.errAt.get(key) ?? -Infinity) < 1000) { if (full) drop(e.source, 1); return }
|
|
482
|
+
if (mine.errors >= 50) { drop('errors', 1); return }
|
|
434
483
|
mine.errors++
|
|
435
484
|
mine.errAt.set(key, now)
|
|
436
485
|
const stack = Array.isArray(e.stack) ? e.stack.slice(0, 3).map((l) => bound(l)).filter((l): l is string => !!l) : stackLines(e.stack)
|
|
437
|
-
|
|
486
|
+
const modes = full ? modesOn() : []
|
|
487
|
+
rec('error', ownerId(), { source: e.source, frame: bound(e.frame), component: bound(e.component), message, ...(stack?.length ? { stack } : {}), ...(L?.done ? { late: true } : {}), ...(full ? e.fields : {}), ...(modes.length ? { modes } : {}) })
|
|
488
|
+
if (modes.length) errorCounted(modes)
|
|
438
489
|
} finally { inError = false }
|
|
439
490
|
}
|
|
491
|
+
// the signals stream's way in (recorder-signals.ts never imports this module)
|
|
492
|
+
signalSink.error = (e) => { if (on) logError(e) }
|
|
493
|
+
signalSink.dropped = (reason, n) => { if (on) drop(reason, n) }
|
|
440
494
|
|
|
441
495
|
// ---- sending ----------------------------------------------------------------------------------------------------
|
|
442
496
|
|
|
443
497
|
const armSend = () => { if (!sending && sendTimer === undefined && outbox.size) sendTimer = setTimeout(() => { sendTimer = undefined; void send() }, SEND_MS) }
|
|
444
498
|
const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
|
|
445
|
-
const post = (records: PerfRecord[], keepalive = false) =>
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
499
|
+
const post = (records: PerfRecord[], keepalive = false) => {
|
|
500
|
+
const t0 = selfCounts.on ? performance.now() : 0 // spec 30 #58: `send`'s own work, and the bytes
|
|
501
|
+
const body = JSON.stringify({ records })
|
|
502
|
+
const sent = api('perf/page', {
|
|
503
|
+
method: 'POST',
|
|
504
|
+
headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
|
|
505
|
+
body,
|
|
506
|
+
...(keepalive ? { keepalive: true } : {}),
|
|
507
|
+
})
|
|
508
|
+
if (selfCounts.on) { selfCounts.bytes += bytesOf(body); perfSeams.selfCost('send', performance.now() - t0) }
|
|
509
|
+
return sent
|
|
510
|
+
}
|
|
451
511
|
const wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))
|
|
452
512
|
/** The `dropped` record that says how many went, when any did (the count starts over). */
|
|
453
513
|
const droppedNow = (more = 0): PerfRecord[] => {
|
|
@@ -484,6 +544,8 @@ async function send(): Promise<void> {
|
|
|
484
544
|
}
|
|
485
545
|
} catch { /* never in the way: what it held is counted below */ }
|
|
486
546
|
if (!ok) { failedSends++; outbox.dropped += batch.filter((r) => r.kind !== 'dropped').length + batch.filter((r) => r.kind === 'dropped').reduce((n, r) => n + (r.n as number), 0) }
|
|
547
|
+
// spec 30 #58: every drop said by a `dropped` record that landed, whatever its reason
|
|
548
|
+
else if (selfCounts.on) selfCounts.dropped += batch.reduce((n, r) => n + (r.kind === 'dropped' ? (r.n as number) || 0 : 0), 0)
|
|
487
549
|
inFlight = []
|
|
488
550
|
sending = false
|
|
489
551
|
armSend()
|
|
@@ -501,10 +563,13 @@ function leave(): void {
|
|
|
501
563
|
if (capturesPending() || WARM) return
|
|
502
564
|
// a send on its way may not outlive the page: its records again (the report drops a duplicate by its seq)
|
|
503
565
|
const all = [...inFlight, ...outbox.takeAll()]
|
|
504
|
-
if (
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
566
|
+
if (all.length) {
|
|
567
|
+
// the cuts first, newest first: the load this page leaves in flight ends in the last of them
|
|
568
|
+
const { fit, lost } = fitWithin(all.filter((r) => r.kind === 'cut').reverse(), all.filter((r) => r.kind !== 'cut'), KEEPALIVE_BYTES)
|
|
569
|
+
try { void post([...fit, ...droppedNow(lost)], true).catch(() => {}) } catch { /* going anyway */ }
|
|
570
|
+
}
|
|
571
|
+
// then the reload lines' share (spec 30 #7), after the page's own
|
|
572
|
+
perfSeams.leaving.emit()
|
|
508
573
|
}
|
|
509
574
|
|
|
510
575
|
// ---- a headless perf run (spec 28 A3.8 #17) ----------------------------------------------------------------------
|
|
@@ -596,9 +661,19 @@ export const recorder = {
|
|
|
596
661
|
if (!L || L.committedAt === undefined || L.cohort) return
|
|
597
662
|
L.cohort = cohortIn(view)
|
|
598
663
|
rec('visible', L.id, { nodes: L.cohort.size, ms: Math.round(performance.now() - L.t0) })
|
|
664
|
+
phase({ phase: 'visible', load: L.id, nodes: L.cohort.size })
|
|
599
665
|
}),
|
|
600
666
|
/** A pan, zoom or layout animation ended (perf.ts). */
|
|
601
|
-
gesture: guard((g: Gesture) => {
|
|
667
|
+
gesture: guard((g: Gesture) => {
|
|
668
|
+
let seen = {}
|
|
669
|
+
// spec 30 #34: what it ended showing, and the documents awake then (iframes minus asleep, as `weight()`)
|
|
670
|
+
if (fullRecorder()) {
|
|
671
|
+
const v = canvasCtl.view()
|
|
672
|
+
seen = { ...(v ? { visible: cohortIn(v).size } : {}), awake: Math.max(0, document.querySelectorAll('iframe.sh-live[src]').length - sleeping()) }
|
|
673
|
+
}
|
|
674
|
+
rec('gesture', ownerId(), { ...g, hz: displayHz() ?? undefined, ...seen })
|
|
675
|
+
settleSoon()
|
|
676
|
+
}),
|
|
602
677
|
/** An error the shell saw: its own (window, ShellBoundary) or the play stage's. A shell error goes out at once. */
|
|
603
678
|
error: guard((e: { source: 'shell' | 'stage'; message: unknown; stack?: unknown; component?: string }) => {
|
|
604
679
|
logError(e)
|