[pypy-issue] Issue #1886: PyPy doesn't do basic loop-invariant optimizations (pypy/pypy)

mario_ issues-reply at bitbucket.org
Sun Oct 12 18:01:32 CEST 2014


New issue 1886: PyPy doesn't do basic loop-invariant optimizations
https://bitbucket.org/pypy/pypy/issue/1886/pypy-doesnt-do-basic-loop-invariant

mario_:

This code can be sped up about 25% by realizing that a[i] is constant in the inner loop.
I know threading potentially invalidates such optimizations but there are some options to work around that.

n = 10**4
a = [list(range(n))]*n

s = 0
for i in range(n):
  #ai = a[i]
  for j in range(n):
    s += a[i][j]

print(s)




More information about the pypy-issue mailing list