Skip to content

Commit c167cf2

Browse files
committed
chore: avoid unnecessary sort to get smallest value
This changes getEarliestTimestamp() to walk the list a single time, instead of performing a full sort, as a sorted list is not needed, just the smallest value.
1 parent e9bf658 commit c167cf2

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

packages/replay-internal/src/eventBuffer/EventBufferArray.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,10 @@ export class EventBufferArray implements EventBuffer {
7373

7474
/** @inheritdoc */
7575
public getEarliestTimestamp(): number | null {
76-
//oxlint-disable-next-line require-array-sort-compare
77-
const timestamp = this.events.map(event => event.timestamp).sort()[0];
78-
79-
if (!timestamp) {
80-
return null;
76+
let ts: number | null = null;
77+
for (const { timestamp } of this.events) {
78+
if (ts === null || timestamp < ts) ts = timestamp;
8179
}
82-
83-
return timestampToMs(timestamp);
80+
return ts === null ? ts : timestampToMs(ts);
8481
}
8582
}

0 commit comments

Comments
 (0)