[Speed] Redundant generic and protocol checks
See original GitHub issueuhohs. @beartype currently exhibits crippling less-than-ideal performance for generics (i.e., user-defined typing.Generic
subclasses) and protocols (i.e., user-defined typing.Protocol
subclasses). As @posita publicly exposed in this hard-hitting journalist expose, this is because @beartype currently generates redundant isinstance()
checks for these subclasses: e.g.,
if not (
isinstance(1, numerary.types.SupportsComplexOps) # <-- this is fine
and
isinstance(1, numerary.types._SupportsComplexOps) # <-- this is badness
):
While technically fine (for various hand-wavy definitions of fine), this redundancy reduces runtime efficiency for generics and protocols involved in complex inheritance hierarchies that make my head spin with dysphoric nausea like last year’s eggnog bender. Just like Santa hopped up on too much Christmas hopium, beartype 0.10.0
promises to fix all the badness.
Let’s keep our promises, @beartype. The reindeer with the blinking nose is depending on us! 🎅
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (8 by maintainers)
Top GitHub Comments
OMG, this is so much better! I noticed one teensy weensy little issue, though. 👌😬 For some reason, the update is getting confused where there there are variadic keyword arguments. Consider:
The
@beartype
decorator will choke when decoratingwhoops
andwhoops_too
.That being said, with some casual testing (selecting from some of
dyce
’s unit tests), I got the following before and after your change:Nice! I now have a hope of landing my no-more-short-circuiting-unions branch!
Awwwwwwwww! What a wonderfully exuberant outpouring of goodwill, festive cheer, and gr8-m8-i-r8-8/8 humour. I really kinda needed this, too. My stepmom was just diagnosed with Stage IV Stomach Cancer (so: terminal, debilitating, and excruciating) the day before Christmas Eve. She’s a delightful woman and I love her to bits. My wife is… well, devastated.
I’m trying not to think about physical reality for a bit by instead beating up manscaped yakuza in Yakuza. But you can only punch so many digital criminal underworld cretins in their plasticky uncanny-valley faces before Ugly Ol’ Reality starts peering over your shoulder and whispering an unintelligible (yet predictably disturbing) catechism in a creepy monotone. And I’m like:
Thank you for the cuddly chuckles. And you’re most welcome, of course! @beartype is here to service numerary’s every need – especially that need for blistering speed that transgresses every local codebase traffic law. Clearly, we’re not quite there yet; we’d love
@beartype
-checked calls to quietly inch within 1.25× or even 1.10× of unchecked calls.We’re confident that our next optimization sprint will lift us up to those lofty heights. Sadly, we didn’t get there for the
beartype 0.10.0
release cycle. I hope to push that out the ice-encrusted cabin door by New Year’s – even though the codebase is mewling with big round eyes for attention, chocolate cookies, and warm hugs. Too bad, bear! You must leave this den.Urgh! So close to perfection. Yet so far from destiny. 🪐