2 ms·
> especially if they could be used in speeding up the execution time Unfortunately I feel like this is where types are least likely to be useful in Ruby and Py
by chrisseaton 10y ago
> especially if they could be used in speeding up the execution time
Unfortunately I feel like this is where types are least likely to be useful in Ruby and Python. Static typing means that you know the type of a value coming into your function, but you can achieve exactly the same thing by dynamically profiling the type, just-in-time specialising the function for it, and then on each call all you need to do is check that the type is what was expected. The check will probably be just one machine word comparison. So static typing saves you just one instruction!
However it would remove the time, memory and complexity needed for the profiling. I'm not sure that's really a big overhead though.
I work on implementing existing programming languages using new technology, and in some cases we basically discard static typing information for the purposes of optimisation, because we can work out better information for ourselves at runtime using profiling.