Reputation: 40358
I'm working in Hack, and am trying to figure out "does code run faster if it's typed", as the language will support both dynamic and static typing depending on the header on the file.
What tests would you run to see the efficiency differences between the two?
Upvotes: 1
Views: 308
Reputation: 3187
A recent paper by Facebook Research describing the current state of the HHVM JIT clarifies (emphasis mine):
§2.1 [Hack's] richer type hints are only used by a static type checker and are discarded by the HHVM runtime. The reason for discarding these richer type hints at runtime is that Hack’s gradual type system is unsound. The static type checker is optimistic and it ignores many dynamic features of the language. Therefore, even if a program type checks, different types can be observed at runtime.
The paper goes on to explain how the JIT uses type information to optimize programs, but for the moment that type information doesn't come from type hints. Still a great read, since it seems that you're invested in the performance of HHVM. I also want to point out that optimizing based on type hints has been requested for some time, which suggests that such optimizations will not come anytime soon.
Upvotes: 3