Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/profile-logic/marker-timing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import type {
MarkerTimingAndBuckets,
} from 'firefox-profiler/types';

// Arbitrarily set an upper limit for adding marker depths, avoiding very long
// overlapping marker timings.
const MAX_STACKING_DEPTH = 300;

/**
* This function computes the timing information for laying out the markers in the
* MarkerChart component. Each marker is put into a single row based on its name. In
Expand Down Expand Up @@ -163,6 +167,12 @@ export function getMarkerTiming(
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we add a new markerTiming track, then you rely that the markerTiming entry is empty, and then that markerTiming.end[markerTiming.length - 1] will be undefined, but I think it would be good to be more explicit.
How about keeping the exact same logic to before, but simply add a guard after line 164:

if (markerTimingsForName.length >= MAX_STACKING_DEPTH) {
  // There's too many markers around the same time already, let's ignore this marker.
  continue;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right that we can keep the same logic and add this guard. Initially I came back to using good-old for loop instead of find because sometimes I feel like find is actually slower :) But I did some testing now and it looks like for this case it actually makes it faster. So reverting this to find sounds like a better path forward. Updated the code.

if (markerTimingsForName.length >= MAX_STACKING_DEPTH) {
// There are too many markers stacked around the same time already, let's
// ignore this marker.
continue;
}

// Otherwise, let's add a new row!
const newTiming = emptyTiming({ instantOnly: false });
addCurrentMarkerToMarkerTiming(newTiming);
Expand Down