Skip to content

Commit f6068d1

Browse files
Add verbose perf logging flag
1 parent a4ab7bc commit f6068d1

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

apps/app/src/react/lib/perf.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const PERF_VERBOSE_KEY = 'scPerfVerbose'
2+
3+
export function isPerfVerbose(): boolean {
4+
try {
5+
return localStorage.getItem(PERF_VERBOSE_KEY) === '1'
6+
} catch {
7+
return false
8+
}
9+
}
10+
11+
export function shouldLogPerf(elapsedMs: number, thresholdMs: number): boolean {
12+
return elapsedMs >= thresholdMs || isPerfVerbose()
13+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PeripheralArea } from '../../models/project/Peripheral.js'
44
import { BridgeId, PeripheralId } from '@shared/api'
55
import { protectString } from '@shared/models'
66
import { Bridge, BridgePeripheralSettings } from '../../models/project/Bridge.js'
7+
import { shouldLogPerf } from '../lib/perf.js'
78

89
/**
910
* Information about currently opened project.
@@ -48,7 +49,7 @@ export class ProjectStore {
4849
this._updateAssignedAreas()
4950

5051
const elapsedMs = Math.round(performance.now() - start)
51-
if (elapsedMs >= 50) {
52+
if (shouldLogPerf(elapsedMs, 50)) {
5253
console.info('[perf] projectStore.update', {
5354
elapsedMs,
5455
bridges: Object.keys(project.bridges).length,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '@shared/models'
1212
import { ClientSideLogger } from '../api/logger.js'
1313
import { hashObj } from '../../lib/util.js'
14+
import { shouldLogPerf } from '../lib/perf.js'
1415

1516
export type Resources = Map<ResourceId, ResourceAny>
1617

@@ -102,7 +103,7 @@ export class ResourcesAndMetadataStore {
102103
}
103104

104105
const elapsedMs = Math.round(performance.now() - start)
105-
if (elapsedMs >= 100) {
106+
if (shouldLogPerf(elapsedMs, 100)) {
106107
console.info('[perf] updateResourcesAndMetadata', {
107108
elapsedMs,
108109
resources: resources.length,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ActionAny, RundownActionLight } from '../../lib/triggers/action.js'
2222
import { isEqual } from 'lodash-es'
2323
import { TimelineObj } from '../../models/rundown/TimelineObj.js'
2424
import { assertNever } from '@shared/lib'
25+
import { shouldLogPerf } from '../lib/perf.js'
2526

2627
interface IRundownsItems {
2728
[fileName: string]: IRundownsItem
@@ -124,7 +125,7 @@ export class RundownsStore {
124125
})
125126
})
126127
const elapsedMs = Math.round(performance.now() - start)
127-
if (elapsedMs >= 100) {
128+
if (shouldLogPerf(elapsedMs, 100)) {
128129
console.info('[perf] updateRundown', {
129130
elapsedMs,
130131
groupCount,

0 commit comments

Comments
 (0)