Skip to content

Commit a4ab7bc

Browse files
Add perf logs for startup data updates
1 parent 7261f10 commit a4ab7bc

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

apps/app/src/react/mobx/ProjectStore.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,20 @@ export class ProjectStore {
4242
}
4343

4444
update(project: Project): void {
45+
const start = performance.now()
4546
this.project = project
4647

4748
this._updateAssignedAreas()
49+
50+
const elapsedMs = Math.round(performance.now() - start)
51+
if (elapsedMs >= 50) {
52+
console.info('[perf] projectStore.update', {
53+
elapsedMs,
54+
bridges: Object.keys(project.bridges).length,
55+
assignedAreas: this.assignedAreas.length,
56+
availableAreas: this.availableAreas.length,
57+
})
58+
}
4859
}
4960

5061
private _updateAssignedAreas() {

apps/app/src/react/mobx/ResourcesAndMetadataStore.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export class ResourcesAndMetadataStore {
5050
resources: Array<{ id: ResourceId; resource: ResourceAny | null }>,
5151
metadata: SerializedProtectedMap<TSRDeviceId, MetadataAny | null>
5252
): void {
53+
const start = performance.now()
54+
let updatedResources = 0
55+
let deletedResources = 0
56+
let updatedMetadata = 0
57+
let deletedMetadata = 0
58+
5359
// Resources:
5460
{
5561
for (const { id, resource } of resources) {
@@ -60,37 +66,52 @@ export class ResourcesAndMetadataStore {
6066
if (existingHash !== resourceHash) {
6167
this.resources.set(id, resource)
6268
this.resourceHashes.set(id, resourceHash)
69+
updatedResources += 1
6370
}
6471
} else {
6572
if (this.resources.has(id)) {
6673
this.resources.delete(id)
6774
this.resourceHashes.delete(id)
75+
deletedResources += 1
6876
}
6977
}
7078
}
7179
}
7280

7381
// Metadata:
7482
{
75-
for (const [deviceId, deviceMetadata] of deserializeProtectedMap<TSRDeviceId, MetadataAny | null>(
76-
metadata
77-
).entries()) {
83+
const metadataMap = deserializeProtectedMap<TSRDeviceId, MetadataAny | null>(metadata)
84+
for (const [deviceId, deviceMetadata] of metadataMap.entries()) {
7885
const metadataHash = hashObj(deviceMetadata)
7986

8087
if (deviceMetadata) {
8188
const existingHash = this.metadataHashes.get(deviceId)
8289
if (existingHash !== metadataHash) {
8390
this.metadata.set(deviceId, deviceMetadata)
8491
this.metadataHashes.set(deviceId, metadataHash)
92+
updatedMetadata += 1
8593
}
8694
} else {
8795
if (this.metadata.has(deviceId)) {
8896
this.metadata.delete(deviceId)
8997
this.metadataHashes.delete(deviceId)
98+
deletedMetadata += 1
9099
}
91100
}
92101
}
93102
}
103+
104+
const elapsedMs = Math.round(performance.now() - start)
105+
if (elapsedMs >= 100) {
106+
console.info('[perf] updateResourcesAndMetadata', {
107+
elapsedMs,
108+
resources: resources.length,
109+
updatedResources,
110+
deletedResources,
111+
updatedMetadata,
112+
deletedMetadata,
113+
})
114+
}
94115
}
95116
public isAnyDeviceRefreshing(): boolean {
96117
return this.refreshStatuses.size > 0

apps/app/src/react/mobx/RundownsStore.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ export class RundownsStore {
9292
}
9393

9494
updateRundown = (rundownId: string, rundown: Rundown): void => {
95+
const start = performance.now()
96+
let groupCount = 0
97+
let partCount = 0
98+
let timelineCount = 0
99+
if (rundown) {
100+
groupCount = rundown.groups.length
101+
for (const group of rundown.groups) {
102+
partCount += group.parts.length
103+
for (const part of group.parts) {
104+
timelineCount += part.timeline.length
105+
}
106+
}
107+
}
95108
runInAction(() => {
96109
this._rundownsClean.set(rundownId, rundown)
97110
this._updateRundown(rundownId, rundown)
@@ -110,6 +123,15 @@ export class RundownsStore {
110123
}
111124
})
112125
})
126+
const elapsedMs = Math.round(performance.now() - start)
127+
if (elapsedMs >= 100) {
128+
console.info('[perf] updateRundown', {
129+
elapsedMs,
130+
groupCount,
131+
partCount,
132+
timelineCount,
133+
})
134+
}
113135
}
114136

115137
hasRundown(rundownId: string): boolean {

0 commit comments

Comments
 (0)