Skip to content

Commit

Permalink
Improve profile builder performance (jlfwong#437)
Browse files Browse the repository at this point in the history
Follow up on this PR jlfwong#435. 

Currently, it took roughly 22 seconds to load my 1.3GB file. After inspecting the profiler, there's a large chunk of time spending in Frame.getOrInsert. I figure we can reduce the number of invocations by half. It reduces the load time to roughly 18 seconds.I also tested with a smaller file (~350MB), and it show similar gains, about 15-20%
  • Loading branch information
Goose97 authored and jackerghan committed Jul 28, 2023
1 parent 19f756a commit ad0faed
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 ad0faed

Please sign in to comment.