Skip to content

Conversation

lemnik
Copy link
Contributor

@lemnik lemnik commented Jul 22, 2025

Goal

Avoid precision loss when dealing with the unix timestamp in ReactNative.

Design

Rework the ReactNative Clock.toUnixTimestampNanoseconds to use two number values representing 32bit integers to form two halves of an int64 and convert directly from the format into a string.

Whenever we transfer a timestamp to or from the native layer, the code now uses a string timestamp in the wire format to avoid any loss of precision.

The iOS code also now uses an improved conversion to go from a string representing an int64 to an NSNumber representing the standard iOS unix timestamp and then to an NSDate for compatibility with bugsnag-cocoa-performance.

Testing

Updated the unit tests for the new format, along with more reliable runs of the existing end2end tests.

Copy link

github-actions bot commented Jul 22, 2025

Browser bundle size

NPM build

Package
Before 234.66 kB
After 234.57 kB
± -87 bytes 🎉

CDN build

Unminified Minfied Minified + gzipped
Before 119.04 kB 45.94 kB 13.25 kB
After 119.04 kB 45.95 kB 13.25 kB
± +1 bytes ⚠️ +7 bytes ⚠️ +2 bytes ⚠️

Code coverage

Ok File (✨=New File) Lines Branches Functions Statements
🔴 /home/runner/work/bugsnag-js-performance/bugsnag-js-performance/packages/core/lib/clock.ts 83.33%
(-16.67%)
100%
(+0%)
50%
(-50%)
80%
(-10%)
🔴 /home/runner/work/bugsnag-js-performance/bugsnag-js-performance/packages/platforms/browser/lib/clock.ts 92.59%
(+0.29%)
62.5%
(+0%)
100%
(+0%)
92.68%
(-1.91%)
🔴 /home/runner/work/bugsnag-js-performance/bugsnag-js-performance/packages/platforms/react-native/lib/clock.ts 93.87%
(-6.13%)
73.91%
(-26.09%)
100%
(+0%)
94.54%
(-5.46%)

Total:

Lines Branches Functions Statements
84.79%(+0.21%) 62.59%(+0.33%) 75.28%(+0.03%) 81.74%(+0.26%)

Generated against 9f952e3 on 6 August 2025 at 08:05:04 UTC

@lemnik lemnik force-pushed the PLAT-14566/clock-fixes branch 2 times, most recently from 430cc78 to ae0635d Compare July 30, 2025 08:03
@lemnik lemnik changed the base branch from next to integration/javascript-span-access July 30, 2025 08:04
@lemnik lemnik requested a review from yousif-bugsnag July 30, 2025 08:04
@lemnik lemnik force-pushed the PLAT-14566/clock-fixes branch 2 times, most recently from 4a5c996 to 8cd3a45 Compare July 30, 2025 08:07
yousif-bugsnag
yousif-bugsnag previously approved these changes Jul 30, 2025
lemnik added 2 commits August 6, 2025 08:59
…ixTimestampNanoseconds to avoid representing Unix nanoTime as a `number`
…ll JS/ReactNative timestamps can be sent as strings
@yousif-bugsnag yousif-bugsnag force-pushed the PLAT-14566/clock-fixes branch from 8cd3a45 to 9f952e3 Compare August 6, 2025 07:59
Base automatically changed from integration/javascript-span-access to next August 6, 2025 13:01
@yousif-bugsnag yousif-bugsnag dismissed their stale review August 6, 2025 13:01

The base branch was changed.

Copy link
Member

@gingerbenw gingerbenw left a comment

Choose a reason for hiding this comment

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

Can't quite get my head around some of the maths in lib/clock.ts but the logic is good and I'm happy that the tests cover it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants