Skip to content

Commit e9e826e

Browse files
committed
fix(perf): queue end markers, related to #1786
1 parent 13f650d commit e9e826e

File tree

1 file changed

+39
-1
lines changed
  • packages/app-backend-core/src

1 file changed

+39
-1
lines changed

packages/app-backend-core/src/perf.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,40 @@ export async function performanceMarkStart (
3535
groupId,
3636
},
3737
}, app, ctx)
38+
39+
if (markEndQueue.has(groupKey)) {
40+
const {
41+
app,
42+
uid,
43+
instance,
44+
type,
45+
time,
46+
} = markEndQueue.get(groupKey)
47+
markEndQueue.delete(groupKey)
48+
await performanceMarkEnd(
49+
app,
50+
uid,
51+
instance,
52+
type,
53+
time,
54+
ctx,
55+
)
56+
}
3857
} catch (e) {
3958
if (SharedData.debugInfo) {
4059
console.error(e)
4160
}
4261
}
4362
}
4463

64+
const markEndQueue = new Map<string, {
65+
app: App,
66+
uid: number,
67+
instance: ComponentInstance,
68+
type: string,
69+
time: number,
70+
}>()
71+
4572
export async function performanceMarkEnd (
4673
app: App,
4774
uid: number,
@@ -55,7 +82,18 @@ export async function performanceMarkEnd (
5582
const appRecord = await getAppRecord(app, ctx)
5683
const componentName = await appRecord.backend.api.getComponentName(instance)
5784
const groupKey = `${uid}-${type}`
58-
const { groupId, time: startTime } = appRecord.perfGroupIds.get(groupKey)
85+
const groupInfo = appRecord.perfGroupIds.get(groupKey)
86+
if (!groupInfo) {
87+
markEndQueue.set(groupKey, {
88+
app,
89+
uid,
90+
instance,
91+
type,
92+
time,
93+
})
94+
return
95+
}
96+
const { groupId, time: startTime } = groupInfo
5997
const duration = time - startTime
6098
await addTimelineEvent({
6199
layerId: 'performance',

0 commit comments

Comments
 (0)