[pypy-issue] Issue #2642: Deleting attributes in another module is significantly slower than CPython (pypy/pypy)
afteryu
issues-reply at bitbucket.org
Thu Aug 31 12:12:40 EDT 2017
New issue 2642: Deleting attributes in another module is significantly slower than CPython
https://bitbucket.org/pypy/pypy/issues/2642/deleting-attributes-in-another-module-is
afteryu:
I came across a performance regression on PyPy3 (v5.8.0-beta0) when I was doing some nasty namespace hacks. I tried to narrow the problem down, and found that PyPy3, when deleting attributes of another module, is significantly slower than CPython. Below is the test case I managed to come up with.
In `test.py`:
```python
import foo
def benchmark(func):
from time import perf_counter
def inner():
start = perf_counter()
for i in range(1000000):
func()
end = perf_counter()
print(end - start)
return inner
@benchmark
def add_del():
foo.bar = 'baz'
del foo.bar
if __name__ == '__main__':
add_del()
```
Module `foo` is an empty file. Running `test.py` yields the following results:
```
$ pypy3 -V
Python 3.5.3 (a37ecfe5f142bc971a86d17305cc5d1d70abec64, Jun 10 2017, 18:23:14)
[PyPy 5.8.0-beta0 with GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]
$ python3 -V
Python 3.6.2
$ pypy3 test.py
1.1875620842911303
$ python3 test.py
0.3927199188619852
```
Changing from `del foo.bar` to `delattr(foo, 'bar')` gives similar results. The problem disappears, however, if I were to delete an attribute of a class, or an item in a dictionary.
Thanks a lot.
More information about the pypy-issue
mailing list