Skip to content

Commit

Permalink
fix(apm): Use Performance API for timings when available (#2492)
Browse files Browse the repository at this point in the history
Instead of downgrading to use the dumb performanceFallback, in the
absence of a timeOrigin we can use INITIAL_TIME.

This should give better timings in Safari Web Workers.
  • Loading branch information
rhcarvalho authored Mar 12, 2020
1 parent 098f4b8 commit ef879bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

- [apm] fix: Use Performance API for timings when available, including Web Workers (#2492)

## 5.14.1

- [apm] fix: Check for performance.timing in webworkers (#2491)
Expand Down
14 changes: 3 additions & 11 deletions packages/utils/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,11 @@ export const crossPlatformPerformance: Pick<Performance, 'now' | 'timeOrigin'> =
// is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing.
// tslint:disable-next-line:strict-type-predicates
if (performance.timeOrigin === undefined) {
// For webworkers it could mean we don't have performance.timing then we fallback
// tslint:disable-next-line:deprecation
if (!performance.timing) {
return performanceFallback;
}
// tslint:disable-next-line:deprecation
if (!performance.timing.navigationStart) {
return performanceFallback;
}

// As of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always a
// valid fallback. In the absence of a initial time provided by the browser, fallback to INITIAL_TIME.
// @ts-ignore
// tslint:disable-next-line:deprecation
performance.timeOrigin = performance.timing.navigationStart;
performance.timeOrigin = (performance.timing && performance.timing.navigationStart) || INITIAL_TIME;
}
}

Expand Down

0 comments on commit ef879bf

Please sign in to comment.