Skip to content

co_stacksize estimate can be highly off #68528

Closed

Description

@arigo
mannequin
BPO 24340
Nosy @nascheme, @pitrou, @benjaminp, @methane, @serhiy-storchaka, @1st1
PRs
  • bpo-24340: Fixed a "leak" in the computation of the stack size effect #1938
  • bpo-24340: Fix estimation of the code stack size. #5076
  • 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 2018-01-11.19:28:17.793>
    created_at = <Date 2015-05-31.18:29:54.905>
    labels = ['interpreter-core', '3.7', 'performance']
    title = 'co_stacksize estimate can be highly off'
    updated_at = <Date 2018-01-11.19:28:17.792>
    user = 'https://github.com/arigo'

    bugs.python.org fields:

    activity = <Date 2018-01-11.19:28:17.792>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-01-11.19:28:17.793>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2015-05-31.18:29:54.905>
    creator = 'arigo'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 24340
    keywords = ['patch']
    message_count = 8.0
    messages = ['244552', '295118', '295119', '295122', '305677', '309346', '309347', '309733']
    nosy_count = 7.0
    nosy_names = ['nascheme', 'pitrou', 'benjamin.peterson', 'Arfrever', 'methane', 'serhiy.storchaka', 'yselivanov']
    pr_nums = ['1938', '5076']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue24340'
    versions = ['Python 3.7']

    Activity

    1. arigo commented on May 31, 2015

      arigomannequin
      MannequinAuthor

      The computation of co_stacksize' by the compiler is known to give only an upper bound estimate. http://bugs.python.org/issue1754094 is an example of fixing a "leak" where every repetition of a statement makes co_stacksize' bigger by 1. However, in the whole 3.x series (from at least 3.2), the following simple code, which at runtime requires about 4 or 5 stack slots, leaks 14(!) slots for every `try:' block. Maybe this should be improved to reduce the extreme size of the leak.

      def g():
          try: pass
          except ImportError as e: pass
          try: pass
          except ImportError as e: pass
          try: pass
          except ImportError as e: pass
          ...

      i.e. any function that is big enough to contain 6 try: blocks in sequence will have its stack size overestimated by about 70.

    2. serhiy-storchaka commented on Jun 4, 2017

      @serhiy-storchaka
      Member

      PR 1938 tries to balance the stack effect computation for try/except and try/finally. I'm not sure that it is worth backporting.

      Noised Antoine and Benjamin as people related to bpo-3021.

    3. pitrou commented on Jun 4, 2017

      @pitrou
      Member

      I'm against backporting performance improvements which don't fix a severe regression.

    4. serhiy-storchaka commented on Jun 4, 2017

      @serhiy-storchaka
      Member

      This isn't so easy. Seems the simplest way to solve this issue is implementing bpo-17611.

    5. nascheme commented on Nov 6, 2017

      @nascheme
      Member

      The WIP pull request PR# 2827 seems to help. The following code prints 86 on python3.6 and 25 with PR 2827 applied.

      def g():
          try: pass
          except ImportError as e: pass
          try: pass
          except ImportError as e: pass
          try: pass
          except ImportError as e: pass
          try: pass
          except ImportError as e: pass
          try: pass
          except ImportError as e: pass
          try: pass
          except ImportError as e: pass
      print(g.__code__.co_stacksize)
    6. serhiy-storchaka commented on Jan 1, 2018

      @serhiy-storchaka
      Member

      With PR 5076 the result of the above example is 10.

    7. serhiy-storchaka commented on Jan 1, 2018

      @serhiy-storchaka
      Member

      Tests originally based on Antoine's tests added for PR 2827.

    8. serhiy-storchaka commented on Jan 9, 2018

      @serhiy-storchaka
      Member

      New changeset d4864c6 by Serhiy Storchaka in branch 'master':
      bpo-24340: Fix estimation of the code stack size. (bpo-5076)
      d4864c6

    9. 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

      3.7 (EOL)end of lifeinterpreter-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