question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is `beartype.door` still O(1)?

See original GitHub issue

This commit is extremely exciting. I really like the typechecking ideas in awfutils, and this is something I’ve been hoping to see in @beartype for a long time. However, I worry about the overhead involved in inserting tons of assert() calls within the bodies of potentially every function in a codebase. I sometimes write code where almost half the statements in a function are annotated with an inline hint. In a 7-figure line count codebase, won’t we run into significant performance overhead, even if the typechecking itself is O(1) in the data?

Can anyone think of any easy way to benchmark this?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
langfieldcommented, Sep 6, 2022

Right. The time complexity of PEP 526 compliance over the lifetime of a Python process could be considered O(k) time for k the total number of annotated assignments repeatedly type-checked by @beartype. Each k incurs a real-world wall-clock cost of at most 1μs, assuming no crimes against humanity like __isinstancecheck__() . For all k < 1,000,000, the total real-world wall-clock costs should still be less than a second over the entire lifetime of the current process and thus imperceptible to glorious fleshy meat suits such as ourselves.

Well, you’ve got me there! Sounds like it’s a non-issue, despite being O(k) in the number of annotations. As for the import hooks. Well, all I have to say is that when you’re taking an extreme measure (and I think doing all of this is an extreme measure), it seems polite to make the toggles opt-in instead of opt-out. I suppose the whole thing is of course opt-in. One of the things I like about the existing decorator is that it is very explicit. Import hooks scare me because I think I might forget that I’m using them, and leave them on when for some reason or another they shouldn’t be.

Anyhow, I think the concern has been addressed. Feel free to close!

0reactions
leyceccommented, Sep 6, 2022

Import hooks scare me because I think I might forget that I’m using them, and leave them on when for some reason or another they shouldn’t be.

Right? Import hooks fundamentally violate Python’s “Explicit is better than implicit!” maxim, which is perhaps not so good. My cynical suspicion, however, is that most users simply don’t care about purist ideology the way we do. As typing zealots, we’re mostly fine with all of the manual legwork that @beartype currently mandates. This is a useful tradeoff for people like us, because we retain full and total control over runtime type-checking over all time and space. In return, all @beartype demands is our scarce minutes, precious lifeblood, and eternal souls.

But most users aren’t like us. Most users don’t have the resources or inclination to manually manage boilerplate churn like that. Decorating every class and callable across a million-line codebase with @beartype.beartype is a hard blocker – and I feel that real-world pain. It’s understandable.

Import hooks fill that adoption gap by eliminating the current prohibitive cost of @beartype’s buy-in. Gah! Tech jargon, thy name is this thread.

Thanks so much for all the ongoing excitement, @langfield. If you’d like to see whitelisting or blacklisting features like the above @beartype_no_pep526, it’d be great if you could open up a new issue. Remind us all of my hollow promises to do something. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unbearably fast near-real-time runtime type-checking ... - GitHub
Unlike static type checkers, beartype can't be opinionated about things that no one should be. If none of the above still apply, still...
Read more >
GitHub - beartype/beartype: Unbearably fast O(1) runtime type ...
A runtime type checker that uses random sampling of the data being checked. It's very sussy.
Read more >
Customer reviews: BETTERCLOUD Large Locking Cat Jaw ...
1990 Jeep Wrangler 1/2 doors made of scrap I had laying around and the BETTERCLOUD Large Locking Cat Jaw Claw Door Latches w/Installation...
Read more >
Ewok - StarWars.com
The Ewoks are sentient furred bipeds native to the moon of Endor. They are curious individuals that stand about one meter tall. They...
Read more >
2023 Best Colleges with No Application Fee in America - Niche
For a school in one of the most diverse cities in the country, ... It's easy to navigate and get around, but there's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found