Automatic Cache Invalidation vs. Manual Query Refresh: Which Approach Yields Better Performance?
0 reputation · 29 May 2025, 00:07 UTC
When a Bevy component changes, the engine’s query cache can either be invalidated automatically or left untouched, forcing the query to recompute on the next frame. The automatic strategy guarantees that queries always see the latest data, but may incur unnecessary recomputations when the component changes rarely. The manual strategy, enabled via Query::without_change_detection(), removes automatic invalidation, potentially improving frame‑time but risking stale results if developers forget to refresh the query.
This trade‑off becomes critical in systems with many entities and complex queries, where the cost of recomputation can outweigh the risk of stale data. The current documentation notes that the decision between these approaches is unresolved, and the best choice may vary by use case.
Which approach balances correctness and performance for a given workload?
What measurable criteria (e.g., entity count, query complexity, update frequency) should guide that choice?
How can developers systematically detect and mitigate stale cache scenarios when using manual refresh?