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

Reduce the number of imports for functools #75762

Closed

Description

@methane
BPO 31581
Nosy @rhettinger, @terryjreedy, @methane, @serhiy-storchaka
PRs
  • bpo-31581: Reduce the number of imports for functools #3757
  • 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-09-30.07:17:17.520>
    created_at = <Date 2017-09-26.03:51:59.535>
    labels = ['3.7', 'library']
    title = 'Reduce the number of imports for functools'
    updated_at = <Date 2017-09-30.07:17:17.519>
    user = 'https://github.com/methane'

    bugs.python.org fields:

    activity = <Date 2017-09-30.07:17:17.519>
    actor = 'methane'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-09-30.07:17:17.520>
    closer = 'methane'
    components = ['Library (Lib)']
    creation = <Date 2017-09-26.03:51:59.535>
    creator = 'methane'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31581
    keywords = ['patch']
    message_count = 5.0
    messages = ['302998', '302999', '303002', '303366', '303399']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'terry.reedy', 'methane', 'serhiy.storchaka']
    pr_nums = ['3757']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue31581'
    versions = ['Python 3.7']

    Activity

    1. methane commented on Sep 26, 2017

      @methane
      MemberAuthor

      Makes import functools about 1.5 ms faster.

      • heapq is used only when Counter.most_common(n).
      • types and waakref is used only for singledispatch.

      master:

      import time:   - _functools 76 us (self 76 us)
      import time:       - _operator 110 us (self 110 us)
      import time:     - operator 469 us (self 359 us)
      import time:     - keyword 174 us (self 174 us)
      import time:       - _heapq 189 us (self 189 us)
      import time:     - heapq 400 us (self 211 us)
      import time:     - itertools 137 us (self 137 us)
      import time:     - reprlib 231 us (self 231 us)
      import time:     - _collections 142 us (self 142 us)
      import time:   - collections 3006 us (self 1456 us)
      import time:     - collections.abc 191 us (self 191 us)
      import time:   - types 518 us (self 327 us)
      import time:   - weakref 577 us (self 577 us)
      import time: - functools 4903 us (self 729 us)

      patched:

      import time:   - _functools 74 us (self 74 us)
      import time:       - _operator 100 us (self 100 us)
      import time:     - operator 460 us (self 361 us)
      import time:     - keyword 174 us (self 174 us)
      import time:     - itertools 139 us (self 139 us)
      import time:     - reprlib 226 us (self 226 us)
      import time:     - _collections 85 us (self 85 us)
      import time:   - collections 2593 us (self 1512 us)
      import time: - functools 3369 us (self 703 us)
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Sep 26, 2017
    3. serhiy-storchaka commented on Sep 26, 2017

      @serhiy-storchaka
      Member

      Initially my patch for bpo-30152 included the change in collections. But it was removed on Raymond's request.

    4. rhettinger commented on Sep 26, 2017

      @rhettinger
      Contributor

      Go ahead.

    5. terryjreedy commented on Sep 29, 2017

      @terryjreedy
      Member

      An option for deferred imports would be to leave a comment at the top where the import would otherwise be. Example:

      # import types, weakref # Deferred to single_dispatch()

      This accomplishes the PEP-8 purpose of making all dependencies of the module visible at the top.

    6. methane commented on Sep 30, 2017

      @methane
      MemberAuthor

      New changeset 9811e80 by INADA Naoki in branch 'master':
      bpo-31581: Reduce the number of imports for functools (GH-3757)
      9811e80

    7. 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 lifestdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions