Skip to content

Commit

Permalink
Speed up dropFunction by using a typed array instead of a sparse JS a…
Browse files Browse the repository at this point in the history
…rray.

This improves firefox-devtools#4668 from 7.0 seconds to 1.6 seconds.

Before: https://share.firefox.dev/3qP8iB3
After: https://share.firefox.dev/43JVAC8
  • Loading branch information
mstange committed Jun 16, 2023
1 parent 7cc75f6 commit 197e034
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/profile-logic/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,9 @@ export function dropFunction(
const { stackTable, frameTable } = thread;

// Go through each stack, and label it as containing the function or not.
const stackContainsFunc: Array<void | true> = [];
// stackContainsFunc is a stackIndex => bool map, implemented as a U8 typed
// array for better performance. 0 means false, 1 means true.
const stackContainsFunc = new Uint8Array(stackTable.length);
for (let stackIndex = 0; stackIndex < stackTable.length; stackIndex++) {
const prefix = stackTable.prefix[stackIndex];
const frameIndex = stackTable.frame[stackIndex];
Expand All @@ -915,15 +917,15 @@ export function dropFunction(
// This is the function we want to remove.
funcIndex === funcIndexToDrop ||
// The parent of this stack contained the function.
(prefix !== null && stackContainsFunc[prefix])
(prefix !== null && stackContainsFunc[prefix] === 1)
) {
stackContainsFunc[stackIndex] = true;
stackContainsFunc[stackIndex] = 1;
}
}

return updateThreadStacks(thread, stackTable, (stack) =>
// Drop the stacks that contain that function.
stack !== null && stackContainsFunc[stack] ? null : stack
stack !== null && stackContainsFunc[stack] === 1 ? null : stack
);
}

Expand Down

0 comments on commit 197e034

Please sign in to comment.