Skip to content

Commit

Permalink
Improve profile builder performance
Browse files Browse the repository at this point in the history
Profiling shows that a significant amount of time is spent in Frame.getOrInsert. This PR improves that by reducing the amount of calls to said function
  • Loading branch information
Goose97 committed Jun 29, 2023
1 parent 984bf12 commit da4c0b2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,13 @@ export class Profile {
}

export class StackListProfileBuilder extends Profile {
_appendSample(stack: FrameInfo[], weight: number, useAppendOrder: boolean) {
_appendSample(stack: Frame[], weight: number, useAppendOrder: boolean) {
if (isNaN(weight)) throw new Error('invalid weight')
let node = useAppendOrder ? this.appendOrderCalltreeRoot : this.groupedCalltreeRoot

let framesInStack = new Set<Frame>()

for (let frameInfo of stack) {
const frame = Frame.getOrInsert(this.frames, frameInfo)
for (let frame of stack) {
const last = useAppendOrder
? lastOf(node.children)
: node.children.find(c => c.frame === frame)
Expand Down Expand Up @@ -500,8 +499,9 @@ export class StackListProfileBuilder extends Profile {
throw new Error('Samples must have positive weights')
}

this._appendSample(stack, weight, true)
this._appendSample(stack, weight, false)
const frames = stack.map(fr => Frame.getOrInsert(this.frames, fr))
this._appendSample(frames, weight, true)
this._appendSample(frames, weight, false)
}

private pendingSample: {
Expand Down

0 comments on commit da4c0b2

Please sign in to comment.