I recently learned that in #Ruby, `to_proc` on frozen objects (like symbols) is much cheaper than on normal objects (e.g. method objects)
This is important if you're ever using the `&block` syntax.https://robots.thoughtbot.com/blocks-procs-and-enumerable …
-
Show this thread
-
The speed difference is because memory can be allocated more efficiently and the interpreter can skip the "escape analysis" phase when `to_proc`-ing immutable objects.
1 reply 0 retweets 0 likesShow this thread -
Replying to @joelquen
If you're using JRuby, the proc doesn't even get allocated unless you're actually using the variable in a context that requires it to be a proc. If you're just passing it as a block to another method, skips the allocation entirely.
1 reply 1 retweet 0 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.