Please take a look at this pr https://github.com/ruby/ruby/pull/3281
Rewriting the C version to simple ruby:
def tap
yield(self)
self
end
made it work faster.
The popular opinion is code written in C is always faster. This method is very simple in both versions, so why is that? What are the mechanisms at work here?
I'm reasing about Ruby's JIT and AFAIU it includes a few extra steps more than the C code would:
Namely Tokenization and Parsing. Where is this magic coming from?