From f7ed6f4c8250efbac66ac026ef5cbb4fdf412dfb Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Fri, 16 Jun 2023 13:54:52 -0400 Subject: [PATCH] Speed up dropFunction by using a typed array instead of a sparse JS array. This improves #4668 from 7.0 seconds to 1.6 seconds. Before: https://share.firefox.dev/3qP8iB3 After: https://share.firefox.dev/43JVAC8 --- src/profile-logic/transforms.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/profile-logic/transforms.js b/src/profile-logic/transforms.js index e4bf11ac00..9a8f07cc12 100644 --- a/src/profile-logic/transforms.js +++ b/src/profile-logic/transforms.js @@ -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 = []; + // 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]; @@ -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 ); }