Title: feat: WHATWG performance API (hr-time, user timing, performance timeline) by edusperoni · Pull Request #2001 · NativeScript/android · GitHub
Open Graph Title: feat: WHATWG performance API (hr-time, user timing, performance timeline) by edusperoni · Pull Request #2001 · NativeScript/android
X Title: feat: WHATWG performance API (hr-time, user timing, performance timeline) by edusperoni · Pull Request #2001 · NativeScript/android
Description: Description Replaces the bare native {now, timeOrigin} object with a spec-shaped implementation of hr-time, User Timing Level 3 and the performance timeline with PerformanceObserver. performance, Performance, PerformanceEntry, PerformanceMark, PerformanceMeasure, PerformanceObserver and PerformanceObserverEntryList are globals in main and worker isolates alike, with Performance extends EventTarget and WebIDL-shaped descriptors/brands. Stacked on #2000 — review only the last two commits. Architecture All spec logic lives in the internal/performance.js builtin. The native side hands it exactly two things — binding.now() (double ms, monotonic) and binding.timeOrigin (wall-clock ms) — so the file is shared verbatim with the iOS runtime (it differs from iOS's copy by two comment lines only, both naming the Android init entry point). tns::Performance native shim (Performance.h/.cpp) runs post-context in PrepareV8Runtime, after Events::Init/ErrorEvents::Init/StructuredClone::Init. Performance::NowMillis(isolate) is the single native clock hook: future requestAnimationFrame work must read the clock through it (V8 platform monotonic clock, CLOCK_MONOTONIC base) so every JS-visible timestamp shares performance.timeOrigin. Per-worker time origins: origins stay captured per Runtime right after Isolate::New (members renamed to m_timeOriginMonotonic/m_timeOriginRealtimeMs, with public PerformanceNowMillis()/TimeOriginMillis() accessors replacing the private PerformanceNowCallback), so each worker keeps its own timeOrigin — asserted by the worker specs. performance.now() keeps full double precision (no coarsening, Node's choice). New primordials: SymbolToStringTag, NumberIsFinite, ArrayPrototypeSort (plus the matching Number.isFinite entry in the ESLint capturedStatics rule). Frame callbacks are the first consumer (2nd commit) The clock hook exists so JS-visible timestamps share one base, so this PR wires up the runtime's existing frame callbacks rather than leaving the hook unused. Two-argument contract: __postFrameCallback now calls back with (frameTimeNanos, performanceMillis). The first argument is unchanged — raw CLOCK_MONOTONIC nanos, which @nativescript/core divides by 1e6 — so this is additive and nothing breaks; the second is the same instant on the performance timeline, comparable with performance.now(). Core can migrate to the second argument at its own pace. Exact, not resampled: Choreographer stamps frames on the very clock the time origin is captured on, so Performance::MonotonicNanosToTimelineMillis() just subtracts the new Runtime::TimeOriginMonotonicMillis(). Verified on device: the origin implied by the two arguments matches the one implied by (System.nanoTime(), performance.now()). The whole minSdk range is covered now. AChoreographer only exists from API 24, so on API 21–23 __postFrameCallback existed but silently never fired. The machinery moves out of CallbackHandlers into FrameCallbacks.{h,cpp}, and API 21–23 goes through android.view.Choreographer via a new com.tns.FrameCallbacks (same entry, same two arguments, per-thread so workers schedule against their own looper). Cleanups carried by the move: entries live behind unique_ptr so both implementations can hand the platform a stable pointer; isolate teardown no longer erases while iterating; and the pre-API-29 AChoreographer entry point's frame time is widened to 64 bits, which it is not on the 32-bit ABIs (the reason postFrameCallback64 exists). Debug runtimes expose __setFrameCallbackImpl (absent from release) so the Java bridge is selectable on a modern device — otherwise it would ship with no device coverage. detail is structured-cloned Building on #2000: mark/measure detail is cloned once at entry creation through the structuredClone global, so entries hold snapshots and an uncloneable detail throws the DataCloneError-named error. The builtin keeps an identity fallback so the file stays portable to a runtime shipping the Performance API before structuredClone. This is the Android side of the iOS follow-up commit 6dd55238d. Deviations (documented in docs/performance.md) User-timing buffers are unbounded (per spec); clearMarks()/clearMeasures() is the release valve. Observer callbacks are delivered from a microtask (still asynchronous relative to mark()/measure()); callback exceptions route to reportError, so one throwing observer does not starve the others. No DOMException: the spec'd SyntaxError/InvalidModificationError are Error instances with name patched. Browser-only surface absent: no resource/navigation timing, no eventCounts. Does your commit message include the wording below to reference a specific issue in this repo? No — this is not tracked by an issue in this repo. Related Pull Requests NativeScript/ios#430 — the iOS PR this mirrors NativeScript/ios@6dd55238d — the iOS detail structured-clone follow-up this also mirrors #2000 — the base branch (feat/structured-clone), whose structuredClone global the detail clone goes through Does your pull request have unit tests? Yes. The cross-runtime shared suite (test-app/app/src/main/assets/app/shared/Performance, already at the pin this branch inherits) is registered from mainpage.js, contributing 56 specs — hr-time invariants, the full measure() options algebra, the timeline queries, observer semantics including buffered replay and takeRecords, detail snapshotting plus the DataCloneError case, and worker time-origin/buffer isolation. The suite gates itself on the API being present, so an unguarded Performance API canary was added to testRuntimeImplementedAPIs.js (mirroring iOS) to make a regression fail rather than silently skip. testPerformanceNow.js is removed — the shared suite supersedes it, as on iOS. The frame-callback contract is covered by 4 new specs in testPostFrameCallback.js, run twice over — once per implementation — asserting the raw first argument stays boot-scale nanoseconds, that the second argument sits on the performance base (never ahead of a performance.now() read taken inside the callback, within a frame of it), that both advance across consecutive frames, and that the origin the two arguments imply matches the one (System.nanoTime(), performance.now()) implies. The results XML confirms the Java implementation suite ran with 2 tests / 0 skipped / 0 failures, so the API 21–23 bridge is device-tested rather than review-only. Verified on an arm64-v8a API 35 emulator: specs failures base (feat/structured-clone, 975e724) 701 0 after the Performance API commit 756 0 this branch 760 0 (+55 = 56 shared Performance specs + 1 canary − 1 self-skip gate spec − 2 superseded testPerformanceNow specs; +4 = the frame-callback specs × 2 implementations.) check_if_tests_passed.js on the pulled results XML: 749 executed, 749 passed, 0 failed. ESLint clean (npm run lint). Summary by CodeRabbit New Features Added a WHATWG-compatible Performance API with timing, marks, measures, entries, observers, and shared clock support. Added performance.now() and timeOrigin for consistent runtime timestamps. Added frame callback scheduling with native and Java Android support, including delayed callbacks. Documentation Added comprehensive Performance API and frame callback documentation, including platform behavior and specification deviations. Tests Expanded coverage for performance APIs, frame timestamps, clock consistency, ordering, and callback progression.
Open Graph Description: Description Replaces the bare native {now, timeOrigin} object with a spec-shaped implementation of hr-time, User Timing Level 3 and the performance timeline with PerformanceObserver. performance, P...
X Description: Description Replaces the bare native {now, timeOrigin} object with a spec-shaped implementation of hr-time, User Timing Level 3 and the performance timeline with PerformanceObserver. performance, P...
Opengraph URL: https://github.com/NativeScript/android/pull/2001
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7b4e0659-53bc-5bf4-f2ef-b79568075cce |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | EB6A:EDA7A:15F9365:1BEE506:6B0133BA |
| html-safe-nonce | 4115381b38bade4adcf96d41b1e855a158ea4231aabfc224e0a59882652d3246 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjZBOkVEQTdBOjE1RjkzNjU6MUJFRTUwNjo2QjAxMzNCQSIsInZpc2l0b3JfaWQiOiI1OTE4MDI5MzUyOTg0OTgyNDU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2ab03bb9adbf5f0e6a6984d7188d9c9a44fbb05e39afff33f3076878a26f0fb6 |
| hovercard-subject-tag | pull_request:4255475536 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/2001/files |
| twitter:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| og:image:alt | Description Replaces the bare native {now, timeOrigin} object with a spec-shaped implementation of hr-time, User Timing Level 3 and the performance timeline with PerformanceObserver. performance, P... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width