I was playing with this simple function to compute uint/3. It does not (afaict) directly allocate any memory, but when run it rapidly consumes all memory (32GB): def divu3(n): q = (n >> 2) + (n >> 4) # q = n*0.0101 (approx). q = q + (q >> 4) # q = n*0.01010101. q = q + (q >> 8) # q = n*0.01010101. q = q + (q >> 16) # q = n*0.01010101. r = n - q*3 # 0 <= r <= 15. return q + (11*r >> 5) # Returning q + r/3. for i in range(2**31): assert(divu3(i) == i/3) Python 2.7.3 (daf1b0412bfbd0666c19d567e37b29e4a3be5734, Jul 12 2013, 19:10:57) [PyPy 2.1.0-beta1 with GCC 4.7.2] on linux2 is it being over eager to specialise? njh
This sounds odd. My PyPy does not leak memory in this example. Can you please double check? On Tue, Jul 30, 2013 at 2:43 AM, Nathan Hurst <njh@njhurst.com> wrote:
I was playing with this simple function to compute uint/3. It does not (afaict) directly allocate any memory, but when run it rapidly consumes all memory (32GB):
def divu3(n): q = (n >> 2) + (n >> 4) # q = n*0.0101 (approx). q = q + (q >> 4) # q = n*0.01010101. q = q + (q >> 8) # q = n*0.01010101. q = q + (q >> 16) # q = n*0.01010101. r = n - q*3 # 0 <= r <= 15. return q + (11*r >> 5) # Returning q + r/3.
for i in range(2**31): assert(divu3(i) == i/3)
Python 2.7.3 (daf1b0412bfbd0666c19d567e37b29e4a3be5734, Jul 12 2013, 19:10:57) [PyPy 2.1.0-beta1 with GCC 4.7.2] on linux2
is it being over eager to specialise?
njh _______________________________________________ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev
Hi, It seems to be range / xrange issue. range allocates all data in a moment when xrange acts like an iterator. On 07/30/2013 01:01 PM, Maciej Fijalkowski wrote:
This sounds odd. My PyPy does not leak memory in this example. Can you please double check?
On Tue, Jul 30, 2013 at 2:43 AM, Nathan Hurst <njh@njhurst.com> wrote:
I was playing with this simple function to compute uint/3. It does not (afaict) directly allocate any memory, but when run it rapidly consumes all memory (32GB):
def divu3(n): q = (n >> 2) + (n >> 4) # q = n*0.0101 (approx). q = q + (q >> 4) # q = n*0.01010101. q = q + (q >> 8) # q = n*0.01010101. q = q + (q >> 16) # q = n*0.01010101. r = n - q*3 # 0 <= r <= 15. return q + (11*r >> 5) # Returning q + r/3.
for i in range(2**31): assert(divu3(i) == i/3)
Python 2.7.3 (daf1b0412bfbd0666c19d567e37b29e4a3be5734, Jul 12 2013, 19:10:57) [PyPy 2.1.0-beta1 with GCC 4.7.2] on linux2
is it being over eager to specialise?
njh _______________________________________________ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev
pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev
Ok, I tracked it down. For some reason pydev (eclipse) was randomly choosing between pypy and python2.7 on each run (I discovered this when watching what was happening in top). This explains why it was so flakey. Sorry for the confusion. I have no idea how I'm going to debug this further. (OT: does anyone recommend a better IDE than pydev+eclipse?) njh On Tue, Jul 30, 2013 at 11:01:30AM +0200, Maciej Fijalkowski wrote:
This sounds odd. My PyPy does not leak memory in this example. Can you please double check?
On Tue, Jul 30, 2013 at 2:43 AM, Nathan Hurst <njh@njhurst.com> wrote:
I was playing with this simple function to compute uint/3. It does not (afaict) directly allocate any memory, but when run it rapidly consumes all memory (32GB):
def divu3(n): q = (n >> 2) + (n >> 4) # q = n*0.0101 (approx). q = q + (q >> 4) # q = n*0.01010101. q = q + (q >> 8) # q = n*0.01010101. q = q + (q >> 16) # q = n*0.01010101. r = n - q*3 # 0 <= r <= 15. return q + (11*r >> 5) # Returning q + r/3.
for i in range(2**31): assert(divu3(i) == i/3)
Python 2.7.3 (daf1b0412bfbd0666c19d567e37b29e4a3be5734, Jul 12 2013, 19:10:57) [PyPy 2.1.0-beta1 with GCC 4.7.2] on linux2
is it being over eager to specialise?
njh _______________________________________________ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev
participants (4)
-
Armin Rigo
-
Maciej Fijalkowski
-
Nathan Hurst
-
Vasily Evseenko