Skip to content

Commit

Permalink
Make sourceFramesInlinedIntoSymbol an Int32Array.
Browse files Browse the repository at this point in the history
This avoids a CompareIC when comparing to null in _createInvertedRootCallNodeTable,
because we'll now only be comparing integers. This speeds up
_createInvertedRootCallNodeTable by almost 2x.
  • Loading branch information
mstange committed Aug 7, 2024
1 parent 1dc1d54 commit 22b07b4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 59 deletions.
16 changes: 8 additions & 8 deletions src/profile-logic/call-node-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class CallNodeInfoNonInvertedImpl implements CallNodeInfo {

sourceFramesInlinedIntoSymbolForNode(
callNodeIndex: IndexIntoCallNodeTable
): IndexIntoNativeSymbolTable | -1 | null {
): IndexIntoNativeSymbolTable | -1 | -2 {
return this._callNodeTable.sourceFramesInlinedIntoSymbol[callNodeIndex];
}
}
Expand All @@ -279,8 +279,8 @@ type InvertedRootCallNodeTable = {|
innerWindowID: Float64Array, // IndexIntoFuncTable -> InnerWindowID
// IndexIntoNativeSymbolTable: all frames that collapsed into this call node inlined into the same native symbol
// -1: divergent: some, but not all, frames that collapsed into this call node were inlined, or they are from different symbols
// null: no inlining
sourceFramesInlinedIntoSymbol: Array<IndexIntoNativeSymbolTable | -1 | null>,
// -2: no inlining
sourceFramesInlinedIntoSymbol: Int32Array, // IndexIntoFuncTable -> IndexIntoNativeSymbolTable | -1 | -2
suffixOrderIndexRangeEnd: Uint32Array, // IndexIntoFuncTable -> SuffixOrderIndex,
length: number,
|};
Expand All @@ -294,8 +294,8 @@ type InvertedNonRootCallNodeTable = {|
innerWindowID: InnerWindowID[], // IndexIntoInvertedNonRootCallNodeTable -> InnerWindowID
// IndexIntoNativeSymbolTable: all frames that collapsed into this call node inlined into the same native symbol
// -1: divergent: some, but not all, frames that collapsed into this call node were inlined, or they are from different symbols
// null: no inlining
sourceFramesInlinedIntoSymbol: Array<IndexIntoNativeSymbolTable | -1 | null>,
// -2: no inlining
sourceFramesInlinedIntoSymbol: Array<IndexIntoNativeSymbolTable | -1 | -2>,
// Non-null for non-root nodes whose children haven't been prepared yet.
suffixOrderedCallNodesSubslice: Array<Uint32Array | null>,
suffixOrderIndexRangeStart: SuffixOrderIndex[],
Expand All @@ -314,7 +314,7 @@ function _createInvertedRootCallNodeTable(
const category = new Int32Array(funcCount);
const subcategory = new Int32Array(funcCount);
const innerWindowID = new Float64Array(funcCount);
const sourceFramesInlinedIntoSymbol = new Array(funcCount);
const sourceFramesInlinedIntoSymbol = new Int32Array(funcCount);
let previousRootSuffixOrderIndexRangeEnd = 0;
for (let funcIndex = 0; funcIndex < funcCount; funcIndex++) {
const callNodesuffixOrderIndexRangeStart =
Expand All @@ -325,7 +325,7 @@ function _createInvertedRootCallNodeTable(
if (
callNodesuffixOrderIndexRangeStart === callNodesuffixOrderIndexRangeEnd
) {
sourceFramesInlinedIntoSymbol[funcIndex] = null;
sourceFramesInlinedIntoSymbol[funcIndex] = -2;
// Leave the remaining columns at zero for this root.
continue;
}
Expand Down Expand Up @@ -994,7 +994,7 @@ export class CallNodeInfoInvertedImpl implements CallNodeInfoInverted {

sourceFramesInlinedIntoSymbolForNode(
callNodeHandle: InvertedCallNodeHandle
): IndexIntoNativeSymbolTable | -1 | null {
): IndexIntoNativeSymbolTable | -1 | -2 {
if (callNodeHandle < this._rootCount) {
const rootFunc = callNodeHandle;
return this._invertedRootCallNodeTable.sourceFramesInlinedIntoSymbol[
Expand Down
2 changes: 1 addition & 1 deletion src/profile-logic/call-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export class CallTree {
const calledFunction = getFunctionName(funcName);
const inlinedIntoNativeSymbol =
this._callNodeInfo.sourceFramesInlinedIntoSymbolForNode(callNodeIndex);
if (inlinedIntoNativeSymbol === null) {
if (inlinedIntoNativeSymbol === -2) {
return undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion src/profile-logic/data-structures.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export function getEmptyCallNodeTable(): CallNodeTable {
category: new Int32Array(0),
subcategory: new Int32Array(0),
innerWindowID: new Float64Array(0),
sourceFramesInlinedIntoSymbol: [],
sourceFramesInlinedIntoSymbol: new Int32Array(0),
depth: [],
maxDepth: -1,
length: 0,
Expand Down
12 changes: 6 additions & 6 deletions src/profile-logic/profile-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function computeCallNodeTable(
const subcategory: Array<IndexIntoSubcategoryListForCategory> = [];
const innerWindowID: Array<InnerWindowID> = [];
const sourceFramesInlinedIntoSymbol: Array<
IndexIntoNativeSymbolTable | -1 | null,
IndexIntoNativeSymbolTable | -1 | -2,
> = [];
let length = 0;

Expand All @@ -168,7 +168,7 @@ export function computeCallNodeTable(
categoryIndex: IndexIntoCategoryList,
subcategoryIndex: IndexIntoSubcategoryListForCategory,
windowID: InnerWindowID,
inlinedIntoSymbol: IndexIntoNativeSymbolTable | null
inlinedIntoSymbol: IndexIntoNativeSymbolTable | -1 | -2
) {
const index = length++;
prefix[index] = prefixIndex;
Expand Down Expand Up @@ -221,8 +221,8 @@ export function computeCallNodeTable(
const subcategoryIndex = stackTable.subcategory[stackIndex];
const inlinedIntoSymbol =
frameTable.inlineDepth[frameIndex] > 0
? frameTable.nativeSymbol[frameIndex]
: null;
? (frameTable.nativeSymbol[frameIndex] ?? -2)
: -2;
const funcIndex = frameTable.func[frameIndex];

// Check if the call node for this stack already exists.
Expand Down Expand Up @@ -318,7 +318,7 @@ function _createCallNodeTableFromUnorderedComponents(
category: Array<IndexIntoCategoryList>,
subcategory: Array<IndexIntoSubcategoryListForCategory>,
innerWindowID: Array<InnerWindowID>,
sourceFramesInlinedIntoSymbol: Array<IndexIntoNativeSymbolTable | -1 | null>,
sourceFramesInlinedIntoSymbol: Array<IndexIntoNativeSymbolTable | -1 | -2>,
length: number,
stackIndexToCallNodeIndex: Int32Array
): CallNodeTableAndStackMap {
Expand All @@ -337,7 +337,7 @@ function _createCallNodeTableFromUnorderedComponents(
const categorySorted = new Int32Array(length);
const subcategorySorted = new Int32Array(length);
const innerWindowIDSorted = new Float64Array(length);
const sourceFramesInlinedIntoSymbolSorted = new Array(length);
const sourceFramesInlinedIntoSymbolSorted = new Int32Array(length);
const depthSorted = new Array(length);
let maxDepth = 0;

Expand Down
80 changes: 40 additions & 40 deletions src/test/store/__snapshots__/profile-view.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2287,16 +2287,16 @@ CallNodeInfoNonInvertedImpl {
1,
7,
],
"sourceFramesInlinedIntoSymbol": Array [
null,
null,
null,
null,
null,
null,
null,
null,
null,
"sourceFramesInlinedIntoSymbol": Int32Array [
-2,
-2,
-2,
-2,
-2,
-2,
-2,
-2,
-2,
],
"subcategory": Int32Array [
0,
Expand Down Expand Up @@ -2408,16 +2408,16 @@ CallTree {
1,
7,
],
"sourceFramesInlinedIntoSymbol": Array [
null,
null,
null,
null,
null,
null,
null,
null,
null,
"sourceFramesInlinedIntoSymbol": Int32Array [
-2,
-2,
-2,
-2,
-2,
-2,
-2,
-2,
-2,
],
"subcategory": Int32Array [
0,
Expand Down Expand Up @@ -2597,16 +2597,16 @@ CallTree {
1,
7,
],
"sourceFramesInlinedIntoSymbol": Array [
null,
null,
null,
null,
null,
null,
null,
null,
null,
"sourceFramesInlinedIntoSymbol": Int32Array [
-2,
-2,
-2,
-2,
-2,
-2,
-2,
-2,
-2,
],
"subcategory": Int32Array [
0,
Expand Down Expand Up @@ -2712,16 +2712,16 @@ CallTree {
1,
7,
],
"sourceFramesInlinedIntoSymbol": Array [
null,
null,
null,
null,
null,
null,
null,
null,
null,
"sourceFramesInlinedIntoSymbol": Int32Array [
-2,
-2,
-2,
-2,
-2,
-2,
-2,
-2,
-2,
],
"subcategory": Int32Array [
0,
Expand Down
6 changes: 3 additions & 3 deletions src/types/profile-derived.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ export type CallNodeTable = {
category: Int32Array, // IndexIntoCallNodeTable -> IndexIntoCategoryList
subcategory: Int32Array, // IndexIntoCallNodeTable -> IndexIntoSubcategoryListForCategory
innerWindowID: Float64Array, // IndexIntoCallNodeTable -> InnerWindowID
// null: no inlining
// IndexIntoNativeSymbolTable: all frames that collapsed into this call node inlined into the same native symbol
// -1: divergent: not all frames that collapsed into this call node were inlined, or they are from different symbols
sourceFramesInlinedIntoSymbol: Array<IndexIntoNativeSymbolTable | -1 | null>,
// -2: no inlining
sourceFramesInlinedIntoSymbol: Int32Array,
// The depth of the call node. Roots have depth 0.
depth: number[],
// The maximum value in the depth column, or -1 if this table is empty.
Expand Down Expand Up @@ -189,7 +189,7 @@ export interface CallNodeInfo {
depthForNode(callNodeIndex: IndexIntoCallNodeTable): number;
sourceFramesInlinedIntoSymbolForNode(
callNodeIndex: IndexIntoCallNodeTable
): IndexIntoNativeSymbolTable | -1 | null;
): IndexIntoNativeSymbolTable | -1 | -2;
}

// An index into SuffixOrderedCallNodes.
Expand Down

0 comments on commit 22b07b4

Please sign in to comment.