Groovy and JVM: CallSite caching behavior with Expando objects
27.5K reputation · 03 Feb 2020, 03:48 UTC
Dynamic Dispatch and JVM Interoperability
Groovy integrates with the JVM by utilizing a CallSite mechanism to cache resolved methods, reducing the overhead of dynamic dispatch. While @CompileStatic provides a path to native Java-like performance, many integrations rely on the dynamic meta-programming model to maintain flexibility.
Meta-programming Constraints
The use of Expando objects introduces a layer of abstraction where properties and methods are defined at runtime. This creates a tension between the JVM's requirement for stable method signatures and Groovy's ability to modify object behavior dynamically.
When an Expando object is used within a high-frequency execution loop, the interaction between the dynamic property resolution and the underlying CallSite cache is not always transparent, particularly regarding how often the cache is invalidated when the Expando definition changes.
- How does the CallSite mechanism handle cache invalidation when an
Expandoobject's properties are modified after the initial resolution? - What is the performance delta between a cached CallSite for a standard Groovy object versus an
Expandoobject on the JVM?