Skip to content

Commit 60a506d

Browse files
authored
Improve SampleGraph and HeightGraph performance (#5897)
Some minor perf improvements and code simplifications.
2 parents f258e8b + f8bed2b commit 60a506d

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/components/shared/thread/HeightGraph.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
import { PureComponent } from 'react';
55
import classNames from 'classnames';
6-
import { ensureExists } from 'firefox-profiler/utils/types';
76
import { timeCode } from 'firefox-profiler/utils/time-code';
87
import { getSampleIndexClosestToStartTime } from 'firefox-profiler/profile-logic/profile-data';
98
import { bisectionRight } from 'firefox-profiler/utils/bisect';
@@ -105,6 +104,8 @@ export class ThreadHeightGraph extends PureComponent<Props> {
105104
firstDrawnSampleIndex
106105
);
107106

107+
const idleCategoryIndex = categories.findIndex((c) => c.name === 'Idle');
108+
108109
// Do one pass over the samples array to gather the samples we want to draw.
109110
const regularSamples = {
110111
height: [] as number[],
@@ -127,6 +128,12 @@ export class ThreadHeightGraph extends PureComponent<Props> {
127128
if (sampleTime < nextMinTime) {
128129
continue;
129130
}
131+
132+
const state = sampleSelectedStates[i] as SelectedState;
133+
if (state === SelectedState.FilteredOutByTransform) {
134+
continue;
135+
}
136+
130137
const heightFuncResult = heightFunc(i);
131138
if (heightFuncResult === null) {
132139
continue;
@@ -136,16 +143,11 @@ export class ThreadHeightGraph extends PureComponent<Props> {
136143

137144
const xPos = (sampleTime - range[0]) * xPixelsPerMs;
138145
let samplesBucket;
139-
if (sampleSelectedStates[i] === (SelectedState.Selected as number)) {
146+
if (state === SelectedState.Selected) {
140147
samplesBucket = highlightedSamples;
141148
} else {
142-
const stackIndex = ensureExists(
143-
thread.samples.stack[i],
144-
'A stack must exist for this sample, since a callNodeIndex exists.'
145-
);
146-
const categoryIndex = thread.stackTable.category[stackIndex];
147-
const category = categories[categoryIndex];
148-
if (category.name === 'Idle') {
149+
const categoryIndex = thread.samples.category[i];
150+
if (categoryIndex === idleCategoryIndex) {
149151
samplesBucket = idleSamples;
150152
} else {
151153
samplesBucket = regularSamples;

src/components/shared/thread/SampleGraph.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ class ThreadSampleGraphCanvas extends React.PureComponent<CanvasProps> {
175175
firstDrawnSampleIndex
176176
);
177177

178+
const idleCategoryIndex = categories.findIndex((c) => c.name === 'Idle');
179+
178180
// Do one pass over the samples array to gather the samples we want to draw.
179181
const regularSamples: number[] = [];
180182
const idleSamples: number[] = [];
@@ -188,19 +190,18 @@ class ThreadSampleGraphCanvas extends React.PureComponent<CanvasProps> {
188190
if (sampleTime < nextMinTime) {
189191
continue;
190192
}
191-
const stackIndex = thread.samples.stack[i];
192-
if (stackIndex === null) {
193+
const state = sampleSelectedStates[i] as SelectedState;
194+
if (state === SelectedState.FilteredOutByTransform) {
193195
continue;
194196
}
195197
const xPos =
196198
(sampleTime - rangeStart) * xPixelsPerMs - drawnSampleWidth / 2;
197199
let samplesBucket;
198-
if (sampleSelectedStates[i] === (SelectedState.Selected as number)) {
200+
if (state === SelectedState.Selected) {
199201
samplesBucket = highlightedSamples;
200202
} else {
201-
const categoryIndex = thread.stackTable.category[stackIndex];
202-
const category = categories[categoryIndex];
203-
if (category.name === 'Idle') {
203+
const categoryIndex = thread.samples.category[i];
204+
if (categoryIndex === idleCategoryIndex) {
204205
samplesBucket = idleSamples;
205206
} else {
206207
samplesBucket = regularSamples;

0 commit comments

Comments
 (0)