logoalt Hacker News

zahlmantoday at 4:33 AM1 replyview on HN

I mean, I think that probably is what happens. But then, while it's sped up a lot, the generated bytecode presumably also includes instructions to try the cast and raise that exception when it fails.

(And the possible "JIT hotpath optimization" could be something like, at the bottom level, branch-predicting that cast.)


Replies

mkmccjrtoday at 4:47 AM

Aha, I think I better understand your point: since the generated bytecode includes a cast, my explanation about the optimization is too simplistic.

I haven't actually inspected the emitted bytecode, so I was only reasoning from the observed speedup.

Your point about branch prediction is really interesting; it would explain how the cast becomes almost free once the type is stable in the hot path.

I'm learning a lot from this thread -- thank you for pushing on the details!

show 1 reply