Groovy - The Art of Calling Methods
summary
Three dispatch strategies and measurable tradeoffs: the simple central invoker uses ScriptBytecodeAdapter.invokeMethodN, is easy to implement but causes megamorphic call sites, heavy boxing and very slow performance. Adding call site caching cuts a Fibonacci microbenchmark from ~600 ms to ~100 ms (~6x) by replacing reflection. Primitive optimizations compile guarded fast- and slow-paths, hitting ~50% of Java speed (goal was 10x improvement over Groovy 1) at the cost of larger bytecode. Using invokedynamic reduces boxing (9→5 boxes in the example) and yields shorter bytecode and better JIT opportunities, but still needs guards for categories, metaclass changes and constructor calls.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 0:57Groovy Code
- 2:27Central Invoker
- 4:52Pros Cons
- 14:06Primitive Optimization
- 15:39Basic Optimization
- 17:20JIT
- 20:38Negatives
- 23:05Meter classes
- 27:38Invoke Dynamic
- 28:29Invoke Dynamic Limitations
- 32:12InvokeDynamic
- 33:31Guard
- 36:58Special class conversions
- 38:08Fibonacci example
- 38:54Advantages of invoke dynamic
- 40:56Problems with invoke dynamic
- 43:12Performance comparison
- 44:53Wish list








