@@ -795,15 +795,27 @@ function getDefaultSelectedThreadIndexes(
795795 } )
796796 ) ;
797797 }
798- const defaultThread = _findDefaultThread (
798+
799+ const { threads } = profile ;
800+ if ( threads . length === 0 ) {
801+ throw new Error ( 'Expected to find a thread index to select.' ) ;
802+ }
803+
804+ const threadOrder = defaultThreadOrder (
799805 visibleThreadIndexes ,
800- profile . threads ,
806+ threads ,
801807 threadActivityScores
802808 ) ;
803- const defaultThreadIndex = profile . threads . indexOf ( defaultThread ) ;
804- if ( defaultThreadIndex === - 1 ) {
805- throw new Error ( 'Expected to find a thread index to select.' ) ;
806- }
809+
810+ // Try to find a tab process with the highest activity score. If it can't
811+ // find one, select the first thread with the highest one.
812+ const defaultThreadIndex =
813+ threadOrder . find (
814+ ( threadIndex ) =>
815+ threads [ threadIndex ] . name === 'GeckoMain' &&
816+ threads [ threadIndex ] . processType === 'tab'
817+ ) ?? threadOrder [ 0 ] ;
818+
807819 return new Set ( [ defaultThreadIndex ] ) ;
808820}
809821
@@ -1320,34 +1332,6 @@ function _computeThreadSampleScore(
13201332 return nonIdleSampleCount * referenceCPUDeltaPerInterval ;
13211333}
13221334
1323- function _findDefaultThread (
1324- visibleThreadIndexes : ThreadIndex [ ] ,
1325- threads : RawThread [ ] ,
1326- threadActivityScores : Array < ThreadActivityScore >
1327- ) : RawThread | null {
1328- if ( threads . length === 0 ) {
1329- // Tests may have no threads.
1330- return null ;
1331- }
1332-
1333- const threadOrder = defaultThreadOrder (
1334- visibleThreadIndexes ,
1335- threads ,
1336- threadActivityScores
1337- ) ;
1338-
1339- // Try to find a tab process with the highest activity score. If it can't
1340- // find one, select the first thread with the highest one.
1341- const defaultThreadIndex =
1342- threadOrder . find (
1343- ( threadIndex ) =>
1344- threads [ threadIndex ] . name === 'GeckoMain' &&
1345- threads [ threadIndex ] . processType === 'tab'
1346- ) ?? threadOrder [ 0 ] ;
1347-
1348- return threads [ defaultThreadIndex ] ;
1349- }
1350-
13511335function _indexesAreValid ( listLength : number , indexes : number [ ] ) {
13521336 return (
13531337 // The item length is valid.
0 commit comments