Skip to content

Commit 8e99ba9

Browse files
authored
ref(core): Avoid unnecessary breadcrumbs array mutations (#8957)
This is a micro improvement, but maybe worth it as we can have a lot of breadcrumbs. This ensures we only create a new breadcrumbs array if we exceed the limit. In contrast, currently we'll always create two copies of the breadcrumbs for each added breadcrumb (first for the array spread, then we copy it through the slice), even if we don't really need to do this.
1 parent 8766bdd commit 8e99ba9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/core/src/scope.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,11 @@ export class Scope implements ScopeInterface {
419419
timestamp: dateTimestampInSeconds(),
420420
...breadcrumb,
421421
};
422-
this._breadcrumbs = [...this._breadcrumbs, mergedBreadcrumb].slice(-maxCrumbs);
422+
423+
const breadcrumbs = this._breadcrumbs;
424+
breadcrumbs.push(mergedBreadcrumb);
425+
this._breadcrumbs = breadcrumbs.length > maxCrumbs ? breadcrumbs.slice(-maxCrumbs) : breadcrumbs;
426+
423427
this._notifyScopeListeners();
424428

425429
return this;

0 commit comments

Comments
 (0)