The way this works now, the VariantFunction descriptor will create a new VariantMethod at least for every instance of the parent class, possibly on every lookup of either the primary or one of the variants. This is particularly problematic because instantiating a VariantMethod actually eagerly binds every variant at lookup time.
I believe that we can fix this by changing VariantMethod so that rather than eagerly creating bound method variants for every variant of the primary when instantiated, we have a lookup table that lazily creates them in __getattr__.
The big caveat here is that if you just do it the naive way, I'm fairly certain that it will ruin introspection and (probably ruin documentation generation as a consequence), so I think we'll also have to be clever about the introspection.
The way this works now, the
VariantFunctiondescriptor will create a newVariantMethodat least for every instance of the parent class, possibly on every lookup of either the primary or one of the variants. This is particularly problematic because instantiating aVariantMethodactually eagerly binds every variant at lookup time.I believe that we can fix this by changing
VariantMethodso that rather than eagerly creating bound method variants for every variant of the primary when instantiated, we have a lookup table that lazily creates them in__getattr__.The big caveat here is that if you just do it the naive way, I'm fairly certain that it will ruin introspection and (probably ruin documentation generation as a consequence), so I think we'll also have to be clever about the introspection.