Why is sound gradual typing slow?

123 views Asked by At

There are a whole bunch of articles making the claim that gradual typing is inherently slow. The most shocking claim comes from Takikawa et al (2016) who report a 100-fold slowdown on gradually typed programs.

I simply don't believe it and want to know exactly where the slowdown comes from. I can believe that Typed Racket's implementation of gradual typing is slow, but not that gradual typing would be that slow in general.

Take for example this gradually typed Python program:

x = some_fun()
y: int = x

It is unsound because x can be of another type than int. However, if a smart compiler inserts the equivalent of an assert

x = some_fun()
assert type(x) == int
y: int = x

then the type checking becomes sound. Clearly, even if you insert hundreds of asserts everywhere in a program, a 100-fold slowdown is not realistic. What am I missing here?

0

There are 0 answers