Skip to content

Long constant calculations stall compilation #71882

Closed

Description

@fcostantini
BPO 27695
Nosy @vstinner, @serhiy-storchaka, @ammaraskar, @fcostantini
Superseder
  • bpo-21074: Too aggressive constant folding
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-12-14.13:16:06.605>
    created_at = <Date 2016-08-05.17:39:36.165>
    labels = ['interpreter-core', 'performance']
    title = 'Long constant calculations stall compilation'
    updated_at = <Date 2017-12-14.13:16:06.604>
    user = 'https://github.com/fcostantini'

    bugs.python.org fields:

    activity = <Date 2017-12-14.13:16:06.604>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-12-14.13:16:06.605>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2016-08-05.17:39:36.165>
    creator = 'fcostantini'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 27695
    keywords = []
    message_count = 5.0
    messages = ['272046', '272047', '272050', '272066', '272105']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'SilentGhost', 'serhiy.storchaka', 'ammar2', 'fcostantini']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '21074'
    type = 'resource usage'
    url = 'https://bugs.python.org/issue27695'
    versions = ['Python 2.7', 'Python 3.6']

    Activity

    1. fcostantini commented on Aug 5, 2016

      fcostantinimannequin
      MannequinAuthor

      Hi, we currently are fuzzing Python programs to find valid code that fails to compile. We found this program never finishes its compilation.

      $ echo "raise ValueError ; 2 ** 12345678912345" > inf.py
      $ python -m py_compile inf.py

      We realize the computation is a large one and takes a very long time, in this case the compiler consumes more and more memory over time. Perhaps the compiler shouldn't try to calculate this indefinitely and just return an error.

      Regards

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      performancePerformance or resource usage
      and removed
      buildThe build process and cross-build
      on Aug 5, 2016
    3. SilentGhost commented on Aug 5, 2016

      SilentGhostmannequin
      Mannequin

      On 3.6 it takes a very long time, but it does finish.

      time ./python -c "raise ValueError ; 2 ** 12345678912345"
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
      ValueError

      real 1m35.673s
      user 1m18.952s
      sys 0m16.644s

    4. ammaraskar commented on Aug 5, 2016

      @ammaraskar
      Member

      Just in case anyone is wondering why this happens. The compiler's peephole optimizer will fold constant expressions like

      x = 5 + 5

      into

      x = 10

      More specifically, this bit here:

      case BINARY_POWER:

      I'd say the current behavior of the compilation taking a long time is fine since at runtime it would run the exact same "2 ** 12345678912345" expression and spend a long time/run out of memory.

      However I'd say the fact that this happens so silently can be a "gotcha" in some very rare cases.

    5. vstinner commented on Aug 5, 2016

      @vstinner
      Member

      FYI my Python reimplementation of the bytecode peephole optimizer doesn't
      have this issue. It estimates the size of a**b using exp() and ln()
      functions.
      http://bytecode.readthedocs.io/en/latest/

    6. changed the title [-]Compilation doesnt' end[/-] [+]Long constant calculations stall compilation[/+] on Aug 6, 2016
    7. serhiy-storchaka commented on Aug 6, 2016

      @serhiy-storchaka
      Member

      See also bpo-21074.

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usage

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions