Title: perf: guard ObjectTable with a monitor instead of StampedLock by edusperoni · Pull Request #2103 · NativeScript/android · GitHub
Open Graph Title: perf: guard ObjectTable with a monitor instead of StampedLock by edusperoni · Pull Request #2103 · NativeScript/android
X Title: perf: guard ObjectTable with a monitor instead of StampedLock by edusperoni · Pull Request #2103 · NativeScript/android
Description: Description ObjectTable (added in #2099) guarded its tables with java.util.concurrent.locks.StampedLock: write locks for mutations, optimistic reads elsewhere. On device, StampedLock runs interpreted. It lives in the boot classpath (core-oj) but outside the boot image, and an app's baseline profile can't compile boot-classpath methods. A profile of NativeScript core's apps/automated suite showed StampedLock.tryWriteLock/casState/writeLock/unlockWriteInternal running in the interpreter on the main thread. This replaces it with synchronized (this). An uncontended monitor enter/exit is compiled into every caller. Reads now take the lock too, so the torn-read handling the optimistic path needed (findIdUnlocked, getUnlocked) is gone. A second commit makes the table concurrent on every API level. It was limited to API 24+ only because StampedLock needs it. On API 21–23, argument objects were resolved natively under the isolate lock and new ids took a separate path; now every level registers through findOrRegister. findIdOptimistic is merged into findId, and getOrCreateObjectId takes one lock instead of a lookup followed by a registration. JNI microbenchmarks (debug.ns.jnibench, optimized release, SM-G780G; main and this branch interleaved, 2 passes × 3 runs; median ns): Benchmark main this PR new java.lang.Object() 2763 1528 −45% (6/6 runs faster) lifecycle new java.lang.Object() [alloc, kept alive] 2807 1520 −46% lifecycle JniBench.newObjectInJava() [alloc, kept alive] 2015 1094 −46% static.newObjectOfManyClasses() [16 classes] 1683 1097 −35% static.newObjectInJava() [new wrapper] 1276 954 −25% static.newInstance(extended class) [Java-created] 8974 7419 −17% new Object.extend({})() 3975 3740 −6% contention, 1 thread, no args 3608 2153 −40% callback.noArgs() 479 436 −9% contention, 2 threads, 3 new objects 6101 6305 +3% (1/6) contention, 2 threads, 3 new objects of 16 classes 6295 6487 +3% (0/6) contention, 4 threads, 3 existing objects 3343 3546 +6% (0/6) The other rows are within ±2%. Even after the JIT has compiled it, StampedLock's write path was costly. Known trade-off: when 2–4 Java threads call into JS at the same time, their object-id lookups used to be lock-free optimistic reads and now contend on the monitor: +3..+6% in those benchmarks. Apps run JS on one thread in the common case, where this is a clear win. Real apps: no measurable difference on the template app's cold start (497/491 vs 503/494 ms) or on a 1000-tile flex-wrap mount. The phone was thermally throttling during that comparison, so those numbers only rule out a large effect. Does your commit message include the wording below to reference a specific issue in this repo? No issue. Related Pull Requests #2099 introduced ObjectTable. Does your pull request have unit tests? Yes. The ObjectTable JVM test for concurrent readers and a writer now requires every read of a stable entry to hit; it used to allow optimistic misses. The test for disabled optimistic reads is gone with the flag. JVM tests: 29/29. Full device suite: API 36 emulator: 1551 specs, 0 failures. API 23 emulator (arm64): 1551 specs, 3 failures, the same 3 that main fails on that emulator: a proxy test that matches ByteBuffer.toString()'s newer cap= format; two HTTP module-import tests that time out. On API 23 the harness also reports "App has crashed - ErrorReportActivity" for both main and this PR. run-as ... ls exits 0 there even when the file is missing, so the harness's checks misfire; the results were read from the XML directly. Summary by CodeRabbit Bug Fixes Improved the reliability of object lookups when multiple threads access the runtime, helping ensure stable objects return the correct identifiers. Object registration, lookup, retrieval, and removal now use consistent synchronization, reducing the risk of inconsistent results during concurrent access. Updated object argument handling to register objects without an existing identifier and correctly mark newly registered objects.
Open Graph Description: Description ObjectTable (added in #2099) guarded its tables with java.util.concurrent.locks.StampedLock: write locks for mutations, optimistic reads elsewhere. On device, StampedLock runs interpret...
X Description: Description ObjectTable (added in #2099) guarded its tables with java.util.concurrent.locks.StampedLock: write locks for mutations, optimistic reads elsewhere. On device, StampedLock runs interpret...
Opengraph URL: https://github.com/NativeScript/android/pull/2103
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:4dab37ca-3602-c4de-65a3-ab49114dc593 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 899C:3D97C8:15F106F:1D31969:6B013850 |
| html-safe-nonce | a6ca885b3ced2ba408703fd5abd775f8de12786542b329f1470b0a7a8e18130b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTlDOjNEOTdDODoxNUYxMDZGOjFEMzE5Njk6NkIwMTM4NTAiLCJ2aXNpdG9yX2lkIjoiMjAzNzUyNTIzMjgxNzg3OTEyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8ebec1ca46cebb30be4c8e1c92f02f8f5babd759234021704c9b7ee8fa68ea28 |
| hovercard-subject-tag | pull_request:5260937306 |
| 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/2103/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 ObjectTable (added in #2099) guarded its tables with java.util.concurrent.locks.StampedLock: write locks for mutations, optimistic reads elsewhere. On device, StampedLock runs interpret... |
| 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