Skip to content

Commit 4bd112b

Browse files
authored
Move transparent fill check to a less expensive place. (#5826)
Checking the fill style for each sample has a lot of overhead. As an alternative, we can accumulate the samples but then just skip the drawing at the end. This improves activity graph drawing performance on https://share.firefox.dev/4aqbUN1 by 23%. Before: https://share.firefox.dev/3Oy0NtP After: https://share.firefox.dev/4aqbUN1
2 parents 75f1ddb + 0587601 commit 4bd112b

File tree

4 files changed

+33
-1090
lines changed

4 files changed

+33
-1090
lines changed

src/components/shared/thread/ActivityGraphCanvas.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ export class ActivityGraphCanvas extends React.PureComponent<CanvasProps> {
163163
// previous fill.
164164
let previousUpperEdge = new Float32Array(canvasPixelWidth);
165165
for (const { fillStyle, accumulatedUpperEdge } of fills) {
166+
if (fillStyle === 'transparent') {
167+
// Skip any drawing work for the Idle category.
168+
previousUpperEdge = accumulatedUpperEdge;
169+
continue;
170+
}
171+
166172
ctx.fillStyle = fillStyle;
167173

168174
// Some fills might not span the full width of the graph - they have parts where
@@ -230,7 +236,11 @@ export class ActivityGraphCanvas extends React.PureComponent<CanvasProps> {
230236
function _createDiagonalStripePattern(
231237
chartCtx: CanvasRenderingContext2D,
232238
color: string
233-
): CanvasPattern {
239+
): CanvasPattern | string {
240+
if (color === 'transparent') {
241+
return 'transparent';
242+
}
243+
234244
// Create a second canvas, draw to it in order to create a pattern. This canvas
235245
// and context will be discarded after the pattern is created.
236246
const patternCanvas = document.createElement('canvas');

src/components/shared/thread/ActivityGraphFills.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export type CategoryDrawStyles = ReadonlyArray<{
7373
readonly getSelectedFillStyle: () => string;
7474
readonly getUnselectedFillStyle: () => string;
7575
readonly getSelectedTextColor: () => string;
76-
readonly filteredOutByTransformFillStyle: CanvasPattern;
76+
readonly filteredOutByTransformFillStyle: CanvasPattern | string;
7777
}>;
7878

7979
type SelectedPercentageAtPixelBuffers = {
@@ -322,19 +322,12 @@ export class ActivityGraphFillComputer {
322322
beforeSampleCpuRatio: number,
323323
afterSampleCpuRatio: number
324324
) {
325-
const { rangeEnd, rangeStart, categoryDrawStyles } =
326-
this.renderedComponentSettings;
325+
const { rangeEnd, rangeStart } = this.renderedComponentSettings;
327326
if (sampleTime < rangeStart || sampleTime >= rangeEnd) {
328327
return;
329328
}
330329

331-
const categoryDrawStyle = categoryDrawStyles[category];
332330
const percentageBuffers = this.mutablePercentageBuffers[category];
333-
334-
if (categoryDrawStyle.getSelectedFillStyle() === 'transparent') {
335-
return;
336-
}
337-
338331
const percentageBuffer = this._pickPercentageBuffer(
339332
percentageBuffers,
340333
sampleIndex

0 commit comments

Comments
 (0)