[Python-Dev] eval() slowdown in 2.2 on MacOS X?

Tim Peters tim.one@home.com
Tue, 8 Jan 2002 13:41:37 -0500


[Andrew Kuchling]
> [CC'ed to python-dev, Barbara Mattson]
>
> Barbara's encountered an apparent problem with test_longexp in Python
> 2.2 on MacOS X.  test_longexp creates a big list expression and
> eval()'s it.  The problem is that it takes an exceedingly long time to
> run, at least more than half an hour (at which point she interrupted
> it).
>
> The two curious things are that 1) while test_longexp requires a lot
> of memory and often thrashes on a low-memory machine (I found there
> are 2 or 3 bugs in the SF bugtracker to this effect), the MacOS box in
> question has a gigabyte of RAM, and 2) Python 2.1.1 *doesn't* show the
> problem.

The test takes about 2 seconds on my box (Win98SE, 256MB, 866MHz), in 2.2 or
2.1.1, and I don't know of any Mac-specific code that might get touched here
except for the C library.  So Skip's suggestion to try pymalloc is a good
one -- although it's hard to see in advance why that would make a difference
in this specific case.

> Quoting from her report:
>
> 	I tried the test_longexp by hand:
>
> 	REPS = XXX
> 	l = eval("[" + "2," * REPS + "]")
> 	print len(l)

Break it into smaller steps so we can narrow down possible causes:

REPS = 50000

print "building list guts"
guts = "2," * REPS

print "building input string"
input = "[" + guts + "]"

print "compiling the input string"
code = compile(input, "<input string>", "eval")

print "executing"
thelist = eval(code)

print len(thelist)

When REPS is large, what's the last thing that gets printed before the huge
delay starts?