-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ABCMeta in C #75514
Comments
The idea is that creating ABCs is approximately twice slower than normal classes. Plus there are smaller penalties for various operations with ABCs. This mostly influences the Python interpreter start-up time (because of extensive use of ABCs in importlib), and start-up times of programs that extensively use ABCs. The situation can be improved by rewriting ABCMeta in C. I have a working implementation, but it is far form being ready and still needs some polishing and optimizations (in particular _abc_cache and friends). Already at this stage I have one question (I will add more when they appear while I am finishing the implementation): is it OK to make _abc_cache, _abc_negative_cache, _abc_negative_cache_version, and _abc_registry read-only? The point is that I want to prohibit something like this: MyABC._abc_cache = "Surprise on updating the cache!" thus avoiding many PySet_Check(...) calls. These attributes are not documented and start with underscore. |
Just to be clear, the only ABCs in importlib are in importlib.abc (and used by importlib.util). This does not impact interpreter startup. |
Eric,
Hm, indeed, but I see that module 'abc' is in 'sys.modules', probably it is then only used by 'collections.abc'/'_collections_abc'. This means that the influence of 'ABCMeta' on interpreter start-up time will be smaller than I thought. But still start-up times for projects that actively use ABCs will be influenced by 'ABCMeta'. But what do you think about making private ABC caches read-only attributes? (They are not documented) |
I've heard many anecdotal complaints about the lack of speed of ABCs. Even if it doesn't affect core Python startup, it does affect startup of apps, and if people are afraid to use them because of this, it's reasonable to try to do something about it. |
Since os.environ uses _collections_abc.MutableMapping, importing _collections_abc is not avoidable while startup.
And as you know, typing module will be very common rapidly :) |
Since the number of applications that get along without any file access is probably close to irrelevant, "os" and "io" feel like sufficiently widely used modules to merit being part of a "usual Python startup" benchmark. Maybe we should add one to the benchmark suite? Anyone up for it? |
"python_startup_nosite" benchmark imports io module, You can see it with |
There has been a lot of work by a number of people on this feature leading up to the 3.7.0b1. Thank you! On PR 5273, Yury says that he believes the feature is ready to merge but would prefer an extension until 3.7.0b2 and that Guido has agreed. I'll defer to Yury's judgement on this and somewhat reluctantly allow an extension: there's a lot going on here. Let's try to get it in as soon as we can, please! |
Thank you, Ned! We'll get it merged in the next few days. |
Isn't 800 lines of C code too high price for speeding up ABCs creation? This will save several microseconds per ABC creation. Even if the program creates 1000 ABCs, this can save just several milliseconds at start-up. |
800 lines of C code is not something hard to notice, so I suppose the answer is obvious for all people involved in the work on PR :-)
The correct way to measure this is relative, not absolute. There are just few ABCs used by modules loaded at Python start-up, and it already allowed to save 10% of start-up time. My expectation is that the number will be similar for a typical Python app. Moreover, |
I think it's well worth it. This has long felt as a sore point to me. On Sat, Feb 17, 2018 at 10:27 AM, Ivan Levkivskyi <report@bugs.python.org>
|
Congratulations all on this milestone! And thanks reviewers for your thorough work. |
PR fixes typo in What's new: rewrittent |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: