You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AndroidObjectReferenceManager overrides for CreateGlobalReference,
DeleteGlobalReference, CreateWeakGlobalReference, and
DeleteWeakGlobalReference were unconditionally calling native logging
P/Invokes on every invocation, even when GREF logging was disabled.
While the native side does an early return when LOG_GREF is off, the
managed-to-native transition itself has significant overhead that adds
up in tight loops (e.g. GC bridge processing with thousands of refs).
Changes:
- Guard all 4 logging P/Invoke calls behind `if (Logger.LogGlobalRef)`
early-return checks, matching the existing local ref pattern
- Add managed `_grefc` and `_weak_grefc` counters using Interlocked
to replace the native counter P/Invokes
- Keep the gref_gc_threshold full-GC trigger working unconditionally
- Switch GlobalReferenceCount/WeakGlobalReferenceCount properties to
read from managed counters via Volatile.Read
Performance (physical device, CoreCLR, Release, 3740 objects):
- Bridge cleanup: 385ms → 4ms (~100x improvement)
- Per-object NewGlobalRef overhead: ~7000µs → ~0µs
0 commit comments