@@ -58,8 +58,8 @@ export type CallTreeTimingsInverted = {|
58
58
callNodeSelf : Float32Array ,
59
59
rootTotalSummary : number ,
60
60
sortedRoots : IndexIntoFuncTable [ ] ,
61
- totalPerRootNode : Map < IndexIntoCallNodeTable , number > ,
62
- rootNodesWithChildren : Set < IndexIntoCallNodeTable > ,
61
+ totalPerRootFunc : Float32Array ,
62
+ hasChildrenPerRootFunc : Uint8Array ,
63
63
| } ;
64
64
65
65
export type CallTreeTimings =
@@ -185,8 +185,8 @@ class CallTreeInternalInverted implements CallTreeInternal {
185
185
_callNodeSelf : Float32Array ;
186
186
_rootNodes : IndexIntoCallNodeTable [ ] ;
187
187
_funcCount : number ;
188
- _totalPerRootNode : Map < IndexIntoCallNodeTable , number > ;
189
- _rootNodesWithChildren : Set < IndexIntoCallNodeTable > ;
188
+ _totalPerRootFunc : Float32Array ;
189
+ _hasChildrenPerRootFunc : Uint8Array ;
190
190
_totalAndHasChildrenPerNonRootNode : Map <
191
191
IndexIntoCallNodeTable ,
192
192
TotalAndHasChildren ,
@@ -199,10 +199,10 @@ class CallTreeInternalInverted implements CallTreeInternal {
199
199
this . _callNodeInfo = callNodeInfo ;
200
200
this . _nonInvertedCallNodeTable = callNodeInfo . getNonInvertedCallNodeTable ( ) ;
201
201
this . _callNodeSelf = callTreeTimingsInverted . callNodeSelf ;
202
- const { sortedRoots, totalPerRootNode , rootNodesWithChildren } =
202
+ const { sortedRoots, totalPerRootFunc , hasChildrenPerRootFunc } =
203
203
callTreeTimingsInverted ;
204
- this . _totalPerRootNode = totalPerRootNode ;
205
- this . _rootNodesWithChildren = rootNodesWithChildren ;
204
+ this . _totalPerRootFunc = totalPerRootFunc ;
205
+ this . _hasChildrenPerRootFunc = hasChildrenPerRootFunc ;
206
206
this . _rootNodes = sortedRoots ;
207
207
}
208
208
@@ -212,7 +212,7 @@ class CallTreeInternalInverted implements CallTreeInternal {
212
212
213
213
hasChildren ( callNodeIndex : IndexIntoCallNodeTable ) : boolean {
214
214
if ( this . _callNodeInfo . isRoot ( callNodeIndex ) ) {
215
- return this . _rootNodesWithChildren . has ( callNodeIndex ) ;
215
+ return this . _hasChildrenPerRootFunc [ callNodeIndex ] !== 0 ;
216
216
}
217
217
return this . _getTotalAndHasChildren ( callNodeIndex ) . hasChildren ;
218
218
}
@@ -238,7 +238,7 @@ class CallTreeInternalInverted implements CallTreeInternal {
238
238
239
239
getSelfAndTotal ( callNodeIndex : IndexIntoCallNodeTable ) : SelfAndTotal {
240
240
if ( this . _callNodeInfo . isRoot ( callNodeIndex ) ) {
241
- const total = ensureExists ( this . _totalPerRootNode . get ( callNodeIndex ) ) ;
241
+ const total = this . _totalPerRootFunc [ callNodeIndex ] ;
242
242
return { self : total , total } ;
243
243
}
244
244
const { total } = this . _getTotalAndHasChildren ( callNodeIndex ) ;
@@ -643,9 +643,9 @@ export function getSelfAndTotalForCallNode(
643
643
case 'INVERTED' : {
644
644
const callNodeInfoInverted = ensureExists ( callNodeInfo . asInverted ( ) ) ;
645
645
const { timings } = callTreeTimings ;
646
- const { callNodeSelf, totalPerRootNode } = timings ;
646
+ const { callNodeSelf, totalPerRootFunc } = timings ;
647
647
if ( callNodeInfoInverted . isRoot ( callNodeIndex ) ) {
648
- const total = totalPerRootNode . get ( callNodeIndex ) ?? 0 ;
648
+ const total = totalPerRootFunc [ callNodeIndex ] ;
649
649
return { self : total , total } ;
650
650
}
651
651
const { total } = _getInvertedTreeNodeTotalAndHasChildren (
@@ -693,13 +693,14 @@ export function computeCallTreeTimingsInverted(
693
693
callNodeInfo : CallNodeInfoInverted ,
694
694
{ callNodeSelf, rootTotalSummary } : CallNodeSelfAndSummary
695
695
) : CallTreeTimingsInverted {
696
- const roots = callNodeInfo . getRoots ( ) ;
696
+ const funcCount = callNodeInfo . getFuncCount ( ) ;
697
697
const callNodeTable = callNodeInfo . getNonInvertedCallNodeTable ( ) ;
698
698
const callNodeTableFuncCol = callNodeTable . func ;
699
699
const callNodeTableDepthCol = callNodeTable . depth ;
700
- const totalPerRootNode = new Map ( ) ;
701
- const rootNodesWithChildren = new Set ( ) ;
702
- const seenRoots = new Set ( ) ;
700
+ const totalPerRootFunc = new Float32Array ( funcCount ) ;
701
+ const hasChildrenPerRootFunc = new Uint8Array ( funcCount ) ;
702
+ const seenPerRootFunc = new Uint8Array ( funcCount ) ;
703
+ const sortedRoots = [ ] ;
703
704
for ( let i = 0 ; i < callNodeSelf . length ; i ++ ) {
704
705
const self = callNodeSelf [ i ] ;
705
706
if ( self === 0 ) {
@@ -710,36 +711,25 @@ export function computeCallTreeTimingsInverted(
710
711
// call tree. This is done by finding the inverted root which corresponds to
711
712
// the self function of the non-inverted call node.
712
713
const func = callNodeTableFuncCol [ i ] ;
713
- const rootNode = roots . find (
714
- ( invertedCallNode ) => callNodeInfo . funcForNode ( invertedCallNode ) === func
715
- ) ;
716
- if ( rootNode === undefined ) {
717
- throw new Error (
718
- "Couldn't find the inverted root for a function with non-zero self time."
719
- ) ;
720
- }
721
714
722
- totalPerRootNode . set (
723
- rootNode ,
724
- ( totalPerRootNode . get ( rootNode ) ?? 0 ) + self
725
- ) ;
726
- seenRoots . add ( rootNode ) ;
715
+ totalPerRootFunc [ func ] += self ;
716
+ if ( seenPerRootFunc [ func ] === 0 ) {
717
+ seenPerRootFunc [ func ] = 1 ;
718
+ sortedRoots . push ( func ) ;
719
+ }
727
720
if ( callNodeTableDepthCol [ i ] !== 0 ) {
728
- rootNodesWithChildren . add ( rootNode ) ;
721
+ hasChildrenPerRootFunc [ func ] = 1 ;
729
722
}
730
723
}
731
- const sortedRoots = [ ...seenRoots ] ;
732
724
sortedRoots . sort (
733
- ( a , b ) =>
734
- Math . abs ( totalPerRootNode . get ( b ) ?? 0 ) -
735
- Math . abs ( totalPerRootNode . get ( a ) ?? 0 )
725
+ ( a , b ) => Math . abs ( totalPerRootFunc [ b ] ) - Math . abs ( totalPerRootFunc [ a ] )
736
726
) ;
737
727
return {
738
728
callNodeSelf,
739
729
rootTotalSummary,
740
730
sortedRoots,
741
- totalPerRootNode ,
742
- rootNodesWithChildren ,
731
+ totalPerRootFunc ,
732
+ hasChildrenPerRootFunc ,
743
733
} ;
744
734
}
745
735
0 commit comments