Leveraging Runtime Type Annotations for CPython Performance Improvements

What on earth makes you think that? Is it this stuff?


That’s the regular expression to verify that a number is a float.

A string is not a float — before being converted to a float, it needs to be validated and typed. This is done using regular expressions.

Each character represents a step in the automaton.

Before the decimal point — because in Python, a float can be 1. or 1.0, the characters after the decimal point are optional.

Oh wow. Yeah, then no, this is never worth xD.

I don’t know if optimizing two operations is such a bad thing if it’s for the most widely used interpreter. Keep in mind that this can also have an impact in a loop — in terms of time and energy consumption.

Yes, but that all happens once per literal float at bytecode compile time. Not every time you pass a float to a function.

3 Likes