Optimizer: Expanding Union Types #402
Labels
bb: medium
Medium issue according to bug bounty categorization
bug bounty
This issue is prized out as part of the Bug Bounty Program
enhancement
New feature or request
Is your feature request related to a problem? Please describe.
Currently functions have to decide between performance and generalizability. I.e. a function foo(Union[A, B]) that does internal isinstance checks to distinguish the two types has an inherently higher cost that writing manually foo_A(A) and foo_B(B). However this would lead to code duplication and more difficult mainenance.
Describe the solution you'd like
For any function foo that accepts union type arguments, we automatically generate foo_A and foo_B as described above. All calls to foo where the type of the argument is known at compilation time are remapped to foo_A and foo_B. Inside foo_A and foo_B a simple truth analysis + dead code analysis can remove the redundant isinstance checks. This is an O3 optimization and can come with significant increase in the script size.
Describe alternatives you've considered
None
Additional context
Would i.e. allow more performant Union[int, Fraction] add and mul implementations.
The text was updated successfully, but these errors were encountered: