Hi,
Thanks for your merciful replies.
Short version
-------------------
As you guessed this was not a cython problem, but inherent slowness in
python object creation when the system was getting close to its
limits.
Long version
------------------
Of course I had not investigated the problem enough, and lacking
understanding, wondered if it may be Cython.
It turned out, when I did investigate properly, the routine was just
taking a very long time (10 times longer appending a tuple with two
scalars to a list, compared to appending a scalar to a list).
The kind of thing I was doing was this:
def func(long n1, long n2):
d = {}
cdef long i, j
cdef int a, b
for i in range(n1):
a = i+1
b = i+2
d[i] = []
for j in range(n2):
val = (a, b) # the slow: fast "val = a"
d[i].append(val)
return d
where n1 was around 30K and n2 around 50. Now I reduced the problem,
and timed it, python and cython take 10 times longer for the tuple
case ("val = (a, b)") than the scalar case ("val = a") - just as for
my larger routine.
> Don't worry, that's normal. When Cython creates them, they get stored in
> temporary variables that hold the reference. Adding them to the dict will
> let the dict add another reference, and when the temporary reference is
> taken out of scope, Cython must DECREF it.
Thank you - that was indeed the source of my confusion.
Best,
Matthew
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev