From db0e497cb7da9fd0b7eee6cfef111268f01e2403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Thu, 12 Nov 2026 11:22:30 +0800 Subject: [PATCH 1/3] fix: rebase rolling display projections without rescanning raw samples --- package-lock.json | 4 +- package.json | 2 +- src/line-display-cache.ts | 32 ++++++++++++++-- tests/line-display-cache.test.ts | 52 ++++++++++++++++++++++++++ tests/line-display-integration.test.ts | 38 +++++++++++++++++++ 5 files changed, 122 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 71b5a7b..851d1df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "crychart", - "version": "1.0.1-opentest.25", + "version": "1.0.1-opentest.30", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "crychart", - "version": "1.0.1-opentest.25", + "version": "1.0.1-opentest.30", "devDependencies": { "@types/node": "24.10.0", "esbuild": "0.25.12", diff --git a/package.json b/package.json index 16a43e1..7e0d905 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crychart", - "version": "1.0.1-opentest.29", + "version": "1.0.1-opentest.30", "description": "CRYChart chart engine with streaming data, interactive axes and WebGL rendering", "type": "module", "main": "./dist/crychart.cjs", diff --git a/src/line-display-cache.ts b/src/line-display-cache.ts index 6a783ce..7e580c0 100644 --- a/src/line-display-cache.ts +++ b/src/line-display-cache.ts @@ -77,6 +77,7 @@ export interface LineDisplayStats { reusedTerminalGroups: number; reusedProjectionSamplesThisUpdate: number; projectedSamplesThisUpdate: number; + projectionRebasesThisUpdate: number; selectionDelta?: LedgerWork; } export type LineDisplayResult = @@ -213,6 +214,10 @@ export class LineDisplayCache { } update(request: LineDisplayRequest): LineDisplayResult { + return this.updateProjection(request, true); + } + + private updateProjection(request: LineDisplayRequest, allowRebase: boolean): LineDisplayResult { if (this.disposed) throw new Error('Line display cache is disposed'); const source = request.source, retained = source.nextSampleIndex - source.firstSampleIndex; const extremaPair = acceptsExtremaPair(request.extremaPairProof,source); @@ -223,7 +228,7 @@ export class LineDisplayCache { const stats: LineDisplayStats = {retainedSourceSamples: retained, requestedSourceSamples: 0, selectedDisplaySamples: 0, submittedDisplaySamples: 0, omittedDisplaySamples: 0, summaryPages: 0, summaryBytes: 0, selectionBytes: 0, projectionBytes: 0, cachedSelectionBytes: 0, cachedProjectionBytes: 0, cachedTopologyBytes: 0, reusedSelectionPages: 0, sourceSamplesScannedThisUpdate: 0, boundarySamplesScannedThisUpdate: 0, visitedSummaryNodes: 0, reusedPages: 0, evictedPages: 0, largestSimplifiedPixelSpan: 0, maximumProjectionXError: 0, maximumProjectionYError: 0, sourceReduction: false, displayReduction: false, extremaNeighborsRetained: request.preserveExtremaNeighbors !== false, - reusedTerminalGroups: 0, reusedProjectionSamplesThisUpdate: 0, projectedSamplesThisUpdate: 0}; + reusedTerminalGroups: 0, reusedProjectionSamplesThisUpdate: 0, projectedSamplesThisUpdate: 0, projectionRebasesThisUpdate: 0}; const fallback = (reason: Extract['reason']): LineDisplayResult => {stats.evictedPages += this.pages.size; this.clear(); return {kind: 'fallback', reason, stats};}; if (request.coordinateMode !== 'linear') return fallback('unsupported-transform'); if (retained > 1 && request.monotonicX !== 'verified-strict') return fallback('unverified-x-order'); @@ -604,8 +609,29 @@ export class LineDisplayCache { else {for (const page of this.pages.values()) {stats.cachedSelectionBytes += page.selected?.indices.byteLength ?? 0; stats.cachedProjectionBytes += page.selected?.positions.byteLength ?? 0; stats.cachedTopologyBytes += (page.selected?.groups.byteLength ?? 0) + (page.selected?.groupLookup?.byteLength ?? 0);}} this.state = {identity: source.identity, epoch: source.contentEpoch, binding: request.bindingRevision, projection: selectionPolicyKey, next: source.nextSampleIndex}; if (pageMode) { - // Coverage requires strict projected X. If Float32 relative coordinates - // collapse distinct source X values, atomically use the usual fallback. + // A rolling window can outlive its original projection origin. Recover + // Float32 spacing around the current window before falling back to raw + // geometry. Keep min/max summaries: only display selections/coordinates + // and their GPU/ledger certificates depend on this origin. Re-reading all + // retained source samples here causes periodic stalls at high rates. + if (!strict && allowRebase) { + const center = x(first) / 2 + x(last) / 2; + if (Number.isFinite(center) && center !== origin.x) { + this.origin = {...origin, x: center}; + for (const page of this.pages.values()) page.selected = undefined; + this.pagePackets?.clear(); this.arena?.clear(); this.deltaLedger?.clear(); + const retry = this.updateProjection(request, false); + retry.stats.projectionRebasesThisUpdate++; + // Preserve actual work counters from both attempts, but publish only + // the accepted projection's errors, allocations and geometry counts. + for (const key of ['sourceSamplesScannedThisUpdate', 'boundarySamplesScannedThisUpdate', + 'visitedSummaryNodes', 'projectedSamplesThisUpdate', 'reusedProjectionSamplesThisUpdate', + 'reusedTerminalGroups', 'evictedPages'] as const) retry.stats[key] += stats[key]; + return retry; + } + } + // Even a centered origin cannot represent every possible source spacing. + // Keep the strict-order safety gate and bound recovery to one attempt. if (!strict) return fallback('unverified-x-order'); if (arenaMode) { const template = {strokeGroup: request.strokeGroup ?? this.id, origin: this.origin!, domain: request.domain, clipRect: request.clipRect, thickness: request.style.thickness, color: [...request.style.color] as typeof request.style.color}; diff --git a/tests/line-display-cache.test.ts b/tests/line-display-cache.test.ts index 335c6ee..422a58e 100644 --- a/tests/line-display-cache.test.ts +++ b/tests/line-display-cache.test.ts @@ -206,3 +206,55 @@ test('independent centerline oracle bounds both directions inside each accepted } } }); + +for (const mode of ['pages', 'arena'] as const) test(`${mode} projection recovery retains summaries, peaks and gaps and resumes incremental updates`, () => { + const capacity = 192000 * 60, batch = 192000 * 6, step = 1000 / 192000; + const values = (n: number, first: number) => Float64Array.from({length: n}, (_, i) => (first + i) % 8191 === 0 ? NaN : (first + i) % 997 === 0 ? 1 : 0); + const data = new DataSetXY({schema: {x: {storage: Float64Array, auto: true, pattern: 'progressive'}, y: {storage: Float64Array}}}); + data.setMaxSampleCount(capacity); + data.appendSamples({y: values(capacity, 0)}, {start: 1811059, step}); + const cache = new LineDisplayCache(); + const draw = () => display(cache.update({...request(data, {width: 910, audit: false}), strokeGroup: 42, + packetMode: mode, reuseCertifiedPages: true, reuseUnchangedGroups: true, collectSourceIndices: false})); + try { + draw(); + data.appendSamples({y: values(batch, capacity)}); + const recovered = draw(); + assert.equal(recovered.stats.projectionRebasesThisUpdate, 1); + assert.ok(recovered.stats.sourceSamplesScannedThisUpdate <= batch + 32); + assert.ok(recovered.stats.reusedPages > 2500); + assert.ok(recovered.stats.submittedDisplaySamples < 100000); + let sawPeak = false, sawGap = false; + for (const packet of recovered.packets!) for (let i = 0; i < packet.count; i++) { + const rawX = packet.positions[i * 2]! + packet.origin.x; + const absolute = Math.round((rawX - 1811059) / step); + const rawY = data.getValue('y', absolute - batch)!; + const displayedY = packet.positions[i * 2 + 1]! + packet.origin.y; + if (Number.isNaN(rawY)) {assert.ok(Number.isNaN(displayedY)); sawGap = true;} + else {assert.equal(displayedY, rawY); if (rawY === 1) sawPeak = true;} + if (i) assert.ok(packet.positions[i * 2]! > packet.positions[(i - 1) * 2]!); + } + assert.ok(sawPeak && sawGap); + data.appendSamples({y: values(9600, capacity + batch)}); + const next = draw(); + assert.equal(next.stats.projectionRebasesThisUpdate, 0); + assert.ok(next.stats.sourceSamplesScannedThisUpdate <= 9616); + assert.ok(next.stats.projectedSamplesThisUpdate < 1000); + if (mode === 'arena') { + assert.equal(next.stats.arena!.fullRebuild, false); + assert.ok(next.stats.selectionDelta!.reusedCompletePages > 2500); + } + } finally {cache.dispose(); data.dispose();} +}); + +test('irreducible Float32 spacing still falls back after one bounded projection recovery', () => { + const data = make(1, {start: 0}); + data.appendSamples({y: Float64Array.from({length: 4999}, (_, i) => i % 2)}, {start: 1e12, step: .001}); + const cache = new LineDisplayCache(); + const result = cache.update({...request(data), strokeGroup: 1, packetMode: 'arena'}); + assert.equal(result.kind, 'fallback'); + if (result.kind === 'fallback') assert.equal(result.reason, 'unverified-x-order'); + assert.equal(result.stats.projectionRebasesThisUpdate, 1); + assert.equal(data.getSampleCount(), 5000); + cache.dispose(); data.dispose(); +}); diff --git a/tests/line-display-integration.test.ts b/tests/line-display-integration.test.ts index ad0d762..74fc03f 100644 --- a/tests/line-display-integration.test.ts +++ b/tests/line-display-integration.test.ts @@ -97,3 +97,41 @@ test('explicit display view preserves ordinary translucent raster and complete s assert.deepEqual(data.readBack(),before); }finally{chart.dispose();data.dispose();} }); + +// Real Monitor retention and sample spacing. The first projection origin stays +// behind the rolling window until the tail crosses Float32's 2^16-ms boundary. +test('192kHz 60-second rolling waveform keeps display reduction across Float32 origin drift', () => { + const count = 192000 * 60, batch = 192000 * 6, step = 1000 / 192000; + const chart = new ChartXY({experimentalLineDisplayPixels: 1, experimentalLineDisplayPackets: true, experimentalLineCoverage: true}); + const data = new DataSetXY({schema: {x: {storage: Float64Array, auto: true, pattern: 'progressive'}, y: {storage: Float64Array}}}); + data.setMaxSampleCount(count); + // Isolated peaks retain adjacent samples, including those that collide in + // Float32. Constant data would omit the close neighbors and miss this bug. + const values = (length: number, first = 0) => Float64Array.from({length}, (_, i) => (i + first) % 997 === 0 ? 1 : 0); + data.appendSamples({y: values(count)}, {start: 1811059, step}); + const series = chart.addLineSeries({schema: data.schema}).setDataSet(data).setDataMapping({x: 'x', y: 'y'}); + series.setStrokeStyle(new SolidLine({thickness: 1, fillStyle: new SolidFill({color: ColorRGBA(30, 200, 170, 255)})})); + chart.getDefaultAxisY().setInterval({start: -0.2, end: 1.2}); + try { + let previousOrigin: number | undefined, originChanges = 0; + for (let pass = 0; pass <= 7; pass++) { + if (pass) data.appendSamples({y: values(batch, data.getNextSampleIndex())}); + chart.getDefaultAxisX().setInterval({start: data.getValue('x', 0)!, end: data.getValue('x', count - 1)!}); + const packets = series.drawLineDisplayPackets(rect, rect, 1.5, 1, true); + const stats = series.getLineDisplayStats(); + assert.ok(stats, `pass ${pass}: display cache must not fall back to all ${count} raw samples`); + assert.equal(series.getLineBlockStats(), undefined); + assert.equal(data.getSampleCount(), count); + assert.ok(stats.submittedDisplaySamples < 100000); + if (pass) assert.ok(stats.sourceSamplesScannedThisUpdate <= batch + 32, 'old summary pages must survive a projection rebase'); + const origin = packets[0]!.origin.x; + if (previousOrigin !== undefined && previousOrigin !== origin) originChanges++; + previousOrigin = origin; + for (const packet of packets) { + assert.ok(packet.strictlyMonotonicX); + for (let i = 1; i < packet.count; i++) assert.ok(packet.positions[i * 2]! > packet.positions[(i - 1) * 2]!); + } + } + assert.ok(originChanges >= 2, 'exercise repeated origin recovery, not just initial projection'); + } finally {chart.dispose(); data.dispose();} +}); From 1a225b87791c4a197623dde09cb793b490b87742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Thu, 12 Nov 2026 11:28:51 +0800 Subject: [PATCH 2/3] fix: align runtime version with monitor projection artifact --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 86cd4b7..99e92a1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -79,7 +79,7 @@ export function cryChart(_options: Record = {}) { getChartCount: () => owned.size, }; } -export const version = "1.0.1-opentest.29"; +export const version = "1.0.1-opentest.30"; export class Dashboard { readonly root: HTMLDivElement; private cells = new Map(); From 342284ff51070796b476ad8d66c71873dd39bc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Thu, 12 Nov 2026 14:50:37 +0800 Subject: [PATCH 3/3] fix: keep gallery catalog version aligned with package --- docs/reference-examples.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference-examples.json b/docs/reference-examples.json index 2022538..689cd8d 100644 --- a/docs/reference-examples.json +++ b/docs/reference-examples.json @@ -2,7 +2,7 @@ "schemaVersion": 2, "identity": { "name": "CRYChart", - "packageVersion": "1.0.1-opentest.29", + "packageVersion": "1.0.1-opentest.30", "entry": "examples/official/index.html" }, "count": 167,