Does EF Core Query Compilation Lock Cause Latency Spikes Under Concurrent Requests?
0 reputation · 05 Sept 2024, 04:12 UTC
Goal
To determine whether the internal query‑compilation lock in Entity Framework Core (EF Core) introduces unpredictable latency when multiple concurrent requests trigger new query shapes.
Constraints & Uncertainty
EF Core’s compilation cache is guarded by a per‑AppDomain lock. Under high concurrency, several threads may wait for the lock, potentially delaying the first execution of a query. Additionally, DbContext pooling, connection pooling, and default change‑tracking can interact with this contention in ways that are hard to isolate in a single‑threaded test.
Specific Questions
- Does the query‑compilation lock create measurable latency spikes when many threads request new query shapes simultaneously?
- Can pre‑compiling queries or disabling compilation caching mitigate these spikes without harming performance?
- Under what circumstances does DbContext pooling contribute to latency under concurrent load, and how does this interact with the compilation lock?