Skip to content

Major slowdown on large listcomp #117108

Description

@tim-one

Bug report

Bug description:

That started within the last 48 hours, on the main branch. Here's test code; it's possible it could be simplified

if 1:
    class Obj:
        def __init__(self, i):
            self.val = i

    import sys
    print(sys.version)
    from time import perf_counter as now

    start = now()
    xs = [Obj(i) for i in range(2**21)]
    finish = now()
    print(finish - start)

Under 3.12.2 it takes about a second, but under current main about 21 seconds.

C:\Code\Python\PCbuild>py \MyPy\small.py
3.12.2 (tags/v3.12.2:6abddd9, Feb  6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]
0.9562742999987677

C:\Code\Python\PCbuild>amd64\python.exe \MyPy\small.py
3.13.0a5+ (heads/main:f4cc77d494, Mar 20 2024, 20:28:50) [MSC v.1939 64 bit (AMD64)]
20.99507549998816

If the size of the list is increased, it appears to suffer much worse than linear-time slowdown.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Mar 21, 2024
  2. hauntsaninja commented on Mar 21, 2024

    @hauntsaninja
    Contributor

    It looks like the regression is due to 1530932 / #116206 cc @markshannon

  3. tim-one commented on Mar 21, 2024

    @tim-one
    MemberAuthor

    Thanks - at least the cause is obvious 😆.,

  4. self-assigned this
    on Mar 21, 2024
  5. tim-one commented on Mar 21, 2024

    @tim-one
    MemberAuthor

    Noting that, in the original program that triggered this, disabling gc restored its former speed.

  6. added a commit that references this issue on Mar 22, 2024
  7. added a commit that references this issue on Mar 23, 2024
  8. added a commit that references this issue on Mar 25, 2024
  9. added a commit that references this issue on Mar 26, 2024
  10. pablogsal commented on Mar 26, 2024

    @pablogsal
    Member

    Has this been fixed by either #117120 or #117213?

  11. markshannon commented on Mar 26, 2024

    @markshannon
    Member

    It was fixed by #117120

  12. added 2 commits that reference this issue on Apr 17, 2024
  13. added 2 commits that reference this issue on Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagerelease-blockertype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions