The final question is - should we avoid using Closure.trampoline() then? Absolutely not. If you use recursive calls in the closure, you should consider using the TrampolineClosure to avoid hitting the call stack size limit. The cost of using TrampolineClosure in the statically compiled Groovy code becomes a trouble only when you need to handle hundreds of thousands calls that invoke recursive closure. However, in this case you can also consider refactoring to the tail recursive method call for the best performance. But remember what Donald Knuth said: "Premature optimization is the root of all evil." Use whatever programming construction that works for you (and your team) best, and solve performance problems when they start occurring.

Thank you!

Thank you so much for reading up to this point! I hope this article met your expectations, and you have learned something valuable from it. If you have one more minute, leave me a comment below, please. This way, I can thank you for your time more in person.

And last but not least. If you find this blog post valuable, help me spread the word, please. You can share it on Twitter, LinkedIn, or anywhere else you can think of. This single tweet or post on social media helps a lot. One more time - thank you so much! You’re awesome!