[pypy-issue] Issue #2410: list.sort(key=...) is slow (pypy/pypy)

Carl Friedrich Bolz issues-reply at bitbucket.org
Mon Oct 3 13:27:10 EDT 2016


New issue 2410: list.sort(key=...) is slow
https://bitbucket.org/pypy/pypy/issues/2410/listsort-key-is-slow

Carl Friedrich Bolz:

Tuom Larsen reported this problem on the mailing list. The following code:

``` python
    from random import random
    from time import time

    class point(object):
        def __init__(self, x, y):
            self.x, self.y = x, y

    data = [point(random(), random()) for i in range(2000000)]

    t = time()
    data.sort(key=lambda p:p.x)
    print time() - t
```

is much slower (>3x on my machine) than the manual version:

``` python
    wrapped_data = [(p.x, p) for p in data]
    wrapped_data.sort()
    data = [it[1] for it in wrapped_data]
```

Which is due to a missing JitDriver in the decorate-functionality of the sort implementation. We should fix that.




More information about the pypy-issue mailing list