Skip to content

[iOS/macOS] 0.86 regression: performance.timeOrigin + performance.now() lags Date.now() by total device sleep since boot (now() and timeOrigin use different clocks after #55977) #60450

Done

Description

@will-selfactualize

Description

On iOS and macOS (Mac Catalyst, and the iOS simulator, which uses the host Mac's clocks), performance.timeOrigin + performance.now() lags Date.now() by the device's total sleep time since boot. This is a regression in 0.86.0. It was reported before in #57595, which the bot closed while the root cause was unknown. The root cause is below.

Root cause. After #55977 (commit 6aa99ad, first released in v0.86.0), performance.now() and performance.timeOrigin use different clocks on Apple platforms. Both are in ReactCommon/react/timing/primitives.h:

  • HighResTimeStamp::now() → chronoNow() → on __APPLE__, machAbsoluteTimeToSteadyClockTimePoint() = mach_absolute_time(). This clock stops while the device sleeps.
  • HighResTimeStamp::unsafeOriginFromUnixTimeStamp() → computeUnsafeOriginFromUnixTimeStamp() = system_clock::now() - std::chrono::steady_clock::now(). On Apple's libc++, steady_clock is CLOCK_MONOTONIC_RAW (= mach_continuous_time()), which keeps counting during sleep. Use mach_absolute_time for HighResTimeStamp on Apple platforms #55977's own summary says so.

#55977 moved now() to mach_absolute_time() but left the origin computed against steady_clock. So timeOrigin is roughly "Unix time at boot on the sleep-inclusive clock", while now() is "awake time since boot". Their sum falls behind wall-clock time by exactly the accumulated sleep. That is minutes on a freshly booted device, and days or weeks on a Mac or iPhone that hasn't rebooted in a while. Before 0.86 both values came from steady_clock, which is why 0.83.4 doesn't drift (the data point in #57595).

Impact. Code that builds wall-clock timestamps as timeOrigin + now(), which the HR-Time spec says should approximate the current time, gets timestamps in the past. @sentry/core's timestampInSeconds() is one example: span and log timestamps from 0.86 iOS/macOS apps are backdated, and the ones older than Sentry's retention window are silently dropped at ingestion. Sentry added an init-time workaround in getsentry/sentry-react-native#6654 because of this.

Suggested fix. Compute the origin against the same clock that now() uses, e.g. in computeUnsafeOriginFromUnixTimeStamp():

auto systemNow = std::chrono::system_clock::now();
auto steadyNow = chronoNow(); // was std::chrono::steady_clock::now()
return HighResDuration(systemNow.time_since_epoch() - steadyNow.time_since_epoch());

This also keeps the origin consistent with the REACT_NATIVE_DEBUG timestamp provider. One caveat: as long as now() excludes sleep, timeOrigin + now() still drifts by any sleep after the origin is first read (it's cached). The alternative is to back now() with mach_continuous_time(), but that would undo the UITouch.timestamp compatibility #55977 was made for. Either way, the origin and now() should share a clock.

Steps to reproduce

  1. Run any React Native 0.86 app with Hermes on an iOS simulator, on a Mac Catalyst build, or on an iPhone, after the Mac or device has slept at least once since boot.
  2. Evaluate in JS: Date.now() - (performance.timeOrigin + performance.now()).
  3. Compare with the device's sleep since boot. Natively, that is (mach_continuous_time() - mach_absolute_time()) converted with mach_timebase_info, in ms.

The two numbers match. On a Mac that had slept 2178.8 s since boot, a 0.86.3 Mac Catalyst debug build reported a JS drift of 2178.79 s. A small C++ program on the same machine at the same time printed std::chrono::steady_clock equal to mach_continuous_time() (difference 0.0 ms) and mach_continuous_time() - mach_absolute_time() = 2178.8 s.

Expected: performance.timeOrigin + performance.now() ≈ Date.now() (as on Android, where both values use steady_clock = CLOCK_MONOTONIC, and as in 0.83–0.85).

React Native Version

0.86.3

Affected Platforms

Runtime - iOS, Runtime - macOS (Mac Catalyst)

Output of npx @react-native-community/cli info

React Native 0.86.3, Hermes, Expo SDK 57, New Architecture
macOS 27.2.1, Apple Silicon (arm64)
Xcode 27.2 (27B52)
Measured on a Mac Catalyst debug build; the same lag shows in an iOS simulator build on the same Mac

Stacktrace or Logs

// JS, Mac Catalyst debug build, RN 0.86.3 (Mac asleep 2178.8 s since boot)
Date.now() - (performance.timeOrigin + performance.now())  => 2178790 ms

// Native C++ on the same Mac, same moment
steady_clock - mach_continuous_time = 0.0 ms
mach_continuous_time - mach_absolute_time = 2178.8 s

MANDATORY Reproducer

Reproducer PR: #60451 (changes only RNTesterPlayground.js). Verified on main in an iOS 26.5 simulator: drift 2178.790 s = host sleep since boot (details).

No app-specific code is involved. Paste this into packages/rn-tester/js/examples/Playground/RNTesterPlayground.js (or any screen) and run RNTester on an iOS simulator after the host Mac has slept:

const driftMs = Date.now() - (performance.timeOrigin + performance.now());
console.log('timeOrigin + now() lags Date.now() by', driftMs, 'ms');

The drift grows with each sleep and equals mach_continuous_time() - mach_absolute_time(). Before 0.86 it is ~0 (#57595 reports ~0 on 0.83.4 on the same machine where 0.86 drifted).

Screenshots and Videos

RNTester Playground on an iOS 26.5 simulator showing Date.now() - (performance.timeOrigin + performance.now()) = 2178.790 s

Activity

  1. added
    Needs: Repro
    on Dec 2, 2026
  2. react-native-bot commented on Dec 2, 2026

    @react-native-bot
    Collaborator

    Warning

    Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:


    You can read more about about it on our website: How to report a bug.

  3. added a commit that references this issue on Dec 2, 2026
  4. will-selfactualize commented on Dec 2, 2026

    @will-selfactualize
    Author

    Reproducer: #60451 edits RNTesterPlayground.js to show Date.now() - (performance.timeOrigin + performance.now()) live. On an iOS simulator or device it jumps by the sleep duration after the host Mac or device sleeps; it should stay ~0.

  5. added
    Needs: Attention
    and removed on Dec 2, 2026
  6. will-selfactualize commented on Dec 2, 2026

    @will-selfactualize
    Author

    Reproduced in RNTester on main with the Playground from #60451 (branch at b49769c + the reproducer commit), iOS 26.5 simulator (iPhone 17 Pro), Debug, Hermes prebuilt 260318099.0.2, RN core built from source.

    The Playground shows:

    Date.now() - (performance.timeOrigin + performance.now()) = 2178.790 s
    

    At the same moment on the host Mac, a native program printed mach_continuous_time() - mach_absolute_time() = 2178.790 s of sleep since boot. The two numbers match to the millisecond. No sleep is needed during the test: the simulator inherits the host's clocks, so any Mac that has slept since boot shows the drift as soon as the screen opens.

    Steps: yarn install, cd packages/rn-tester && bundle exec pod install, build the RNTester scheme for a simulator, open the Playground tab.

  7. rubennorte commented on Dec 2, 2026

    @rubennorte
    Member

    Thanks for reporting this!

    Should be fixed in main already :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionNeeds: Repro

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions