JP Camara @jpcamara.com · Jan 14

TIL: In Ruby, there is a significant performance difference between calling `obj.my_method` vs calling `obj.send(:my_method)`. To be clear, "Significant" in this instance is more the realm of microbenchmarks, or very hot code path optimizations (hundreds of thousands/millions of calls). /🧵

20 likes 2 replies

?

Replies

JP Camara · Jan 14

Until more recently, my mental model was a call to `obj.my_method` was basically just a call to `obj.send(:my_method)` behind the scenes. Ruby is all about sending messages to objects, after all. What more explicit way of "send"ing a message was there than to call "send"?! /2

Jean Boussier · Jan 14

Nitpick, the difference is more than 1.5x. In your benchmark, the `.new` shouldn't be part of the bench block.