[Python-Dev] PEP 544: Protocols - second round
INADA Naoki
songofacandy at gmail.com
Wed May 31 07:26:30 EDT 2017
Hi,
I'm interested in startup time too, not only execution time.
Here is very rough test:
with open('with_abc.py', 'w') as f:
print("import abc", file=f)
for i in range(1, 1001):
print(f"class A{i}(metaclass=abc.ABCMeta): pass", file=f)
with open('without_abc.py', 'w') as f:
print("import abc", file=f)
for i in range(1, 1001):
print(f"class A{i}: pass", file=f)
$ time python3 -c 'import abc'
real 0m0.051s
user 0m0.035s
sys 0m0.013s
$ time python3 -c 'import with_abc'
real 0m0.083s
user 0m0.063s
sys 0m0.017s
$ time python3 -c 'import without_abc'
real 0m0.055s
user 0m0.042s
sys 0m0.011s
It seems 1000 ABC classes takes less than 30ms but 1000 normal
classes takes less than 10ms.
I don't know this penalty is acceptable or not.
But how about making ABC optional?
I don't want to use ABC so frequently when there is no real requirement of ABC.
ABC implementation is very complex and sometimes ABC cause unexpected
performance issue, like you fixed in https://github.com/python/typing/pull/383
If we start with "Protocol is always ABC" and we face unexpected
performance penalty later, it may be difficult to find and optimize it.
# If we can stop using ABC for io.IOBase, Python startup time will be
few ms faster.
# Maybe, I should implement weakset and abc in C.
Regards,
More information about the Python-Dev
mailing list