mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-08 15:59:16 +00:00
Replace structuredClone with shape-aware clones in rundown/data hot paths
structuredClone's generic serialization algorithm does far more work than plain object spreads need for these known shapes. Adds cloneEntryData() and cloneRundown() as drop-in replacements (same "independent copy" contract, same call sites) and swaps them in everywhere a rundown or a single entry was being deep-cloned via structuredClone: - createTransaction()/init() in rundown.dao.ts - the main per-mutation clone - DataProvider.setRundown() - was re-cloning the whole rundown a second time on every single commit - rundown.service.ts background-rundown clones (custom field rename/remove, duplicateExistingRundown) - the per-entry clone in processRundown's non-mutating path (rundown.parser.ts) - mergeRundownPreservingFields's per-entry clone Also: - safeMerge() (DataProvider.utils.ts) was deep-cloning the entire DatabaseModel, including all rundowns, just to read a handful of small config properties that never touch rundowns - it now only clones the properties it actually merges. - sheets.service.ts's per-row clone before building a (read-only) Google Sheets cell request was unnecessary and is removed. - runtime.service.ts's previous-state snapshot for eventNow/eventNext/ eventFlag/groupNow now uses cloneEntryData. Benchmarked on a synthetic 1000-event rundown: a cue-only edit (no reprocessing needed) went from ~5ms to ~1.2ms end to end, including the DataProvider clone. Verified against the existing test suite (695 passing) plus typecheck and lint.
This commit is contained in:
@@ -20,6 +20,7 @@ import { triggerAutomations } from '../../api-data/automation/automation.service
|
||||
import { triggerReportEntry } from '../../api-data/report/report.service.js';
|
||||
import { getCurrentRundown, getEntryWithId, getRundownMetadata } from '../../api-data/rundown/rundown.dao.js';
|
||||
import { RundownMetadata } from '../../api-data/rundown/rundown.types.js';
|
||||
import { cloneEntryData } from '../../api-data/rundown/rundown.utils.js';
|
||||
import { logger } from '../../classes/Logger.js';
|
||||
import { timerConfig } from '../../setup/config.js';
|
||||
import { eventStore } from '../../stores/EventStore.js';
|
||||
@@ -754,7 +755,7 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
|
||||
}
|
||||
// at this point we know that either the id or the contents has changed
|
||||
batch.add(key, currentEntry as RuntimeStore[K]); // we know that there is the necessary overlap in the types to cast this
|
||||
RuntimeService.previousState[key] = structuredClone(currentEntry);
|
||||
RuntimeService.previousState[key] = currentEntry ? cloneEntryData(currentEntry) : null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user