logoalt Hacker News

on_the_traintoday at 8:52 PM1 replyview on HN

That's the reason why polymorphism is sometimes described as slow. It's not really slow... But it prevents inlining and therefore always is a function call as opposed to sometimes no function call. It's not the polymorphism is slow. It's that alternatives can sometimes compile to zero


Replies

branko_dtoday at 9:04 PM

On the other hand, if the compiler can prove at compile-time what type the object must have at run-time, it can eliminate the dynamic dispatch and effectively re-enable inlining.

show 1 reply