← 输入框|github.com|刷新
Skip to content

Major slowdown on large listcomp #117108

Closed
Closed

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-bug
    interpreter-core
    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. added
    performance
    on Mar 21, 2024
  5. self-assigned this
    on Mar 21, 2024
  6. 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.

  7. added and removed
    type-bug
    on Mar 21, 2024
  8. added
    type-bug
    on Mar 22, 2024
  9. added a commit that references this issue on Mar 22, 2024
  10. added a commit that references this issue on Mar 23, 2024
  11. added a commit that references this issue on Mar 25, 2024
  12. added a commit that references this issue on Mar 26, 2024
  13. pablogsal commented on Mar 26, 2024

    @pablogsal
    Member

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

  14. markshannon commented on Mar 26, 2024

    @markshannon
    Member

    It was fixed by #117120

  15. added 2 commits that reference this issue on Apr 17, 2024
  16. 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-coreperformancerelease-blockertype-bug

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions