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 (_monodroid_gref_log_new, _monodroid_gref_log_delete,
_monodroid_weak_gref_new, _monodroid_weak_gref_delete) 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 measurable overhead that adds
up when creating/deleting many references in a tight loop (e.g. during
GC bridge processing).
This change wraps the P/Invoke calls in `if (Logger.LogGlobalRef)`
guards, matching the pattern already used for local reference logging
(CreateLocalReference, DeleteLocalReference, etc.).
Note: the native counters (gc_gref_count, gc_weak_gref_count) will not
be updated when logging is off. These counters are only used for
logging output and the GREF threshold GC trigger, both of which are
only relevant when logging is enabled.
0 commit comments