Skip to content

Pathological performance on big list and dict literals #8247

Open
@Phlogistique

Description

@Phlogistique
  • Are you reporting a bug, or opening a feature request?

Reporting a performance issue

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

a.py:

a = [[[[[[[[[[[[[[[[[[[[
    0
]]]]]]]]]]]]]]]]]]]]
time mypy a.py
  • What is the actual behavior/output?

Mypy type-checks the file successfully

  • What is the behavior/output you expect?

Mypy takes an inordinate amount of time to type-check the file.

On my laptop, it takes 13 seconds with 18 levels of nesting, 32 seconds with 19 levels, and 9 minutes 53 seconds with 20 levels of nesting.

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

I am able to reproduce the issue with mypy 0.750 and with mypy master.

  • What are the mypy flags you are using? (For example --strict-optional)

No particular flags. I am able to reproduce the issue with and without --no-incremental.

  • Additional notes:

I experience the same problem with dictionaries:

a = {0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:
    0
}}}}}}}}}}}}}}}}}}}}

My actual use-case involves embedding JSON schemas in Python files, with mypy taking over a minute type-checking a single Python file.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions