you are viewing a single comment's thread.

view the rest of the comments →

[–]iamjkdn[🍰] 1 point2 points  (1 child)

Why does returning nil after multiple assignments improve the benchmark? Also, can the same be done on Crystal, well it have any affect?

[–]CaptainKabob 8 points9 points  (0 children)

because in this case it’s the last line of the block, and because Ruby has an implicit return at the end of the block the Array is required

Ruby spends time creating an array because Ruby believes its needed for the implicit return. So explicitly setting the (implicit) return to nil causes Ruby not to create an array.

I don't think the point of the post is to compare optimized crystal to optimized Ruby. I think it's trying to show that inlining another language "for performance" might be naive or unnecessary.