Xamarin.Android Java.Interop Concurrency Latency
0 reputation · 25 Jun 2026, 23:12 UTC
The Xamarin.Android Java.Interop layer measures latency when multiple managed threads invoke the same native Java method concurrently. Under low concurrency (1‑2 threads) marshalling adds ~0.2‑0.5 ms per call, but with eight or more threads the average latency rises to 2‑5 ms because of lock contention protecting the JNIEnv pointer and mono runtime GC safe‑points.
This behavior is documented across Xamarin.Android releases 12.2‑13.0, Release builds with linking set to “Link Framework Assemblies Only”, API level 30, and persists regardless of ART ahead‑of‑time hybrid compilation, indicating the bottleneck resides in the interop serialization rather than method execution.
Should Xamarin expose a per‑thread JNIEnv cache to eliminate shared‑monitor contention? Is a lock‑free interop API preferable for high‑concurrency scenarios? Which approach yields lower latency when eight or more threads run simultaneously?