Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup Enum lookup #79766

Closed
asvetlov opened this issue Dec 26, 2018 · 3 comments
Closed

Speedup Enum lookup #79766

asvetlov opened this issue Dec 26, 2018 · 3 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir

Comments

@asvetlov
Copy link
Contributor

BPO 35585
Nosy @asvetlov, @ethanfurman
PRs
  • bpo-35585: Speed up enum by-value lookup #11318
  • bpo-35585: Speed up enum by-value lookup #11318
  • [3.7] bpo-35585: Speed-up building enums by value, e.g. http.HTTPStatus(200) (GH-11318) #11324
  • 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 = 'https://github.com/ethanfurman'
    closed_at = <Date 2018-12-26.20:52:32.162>
    created_at = <Date 2018-12-26.00:26:24.805>
    labels = ['3.8', '3.7', 'library']
    title = 'Speedup Enum lookup'
    updated_at = <Date 2018-12-26.20:52:32.162>
    user = 'https://github.com/asvetlov'

    bugs.python.org fields:

    activity = <Date 2018-12-26.20:52:32.162>
    actor = 'asvetlov'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2018-12-26.20:52:32.162>
    closer = 'asvetlov'
    components = ['Library (Lib)']
    creation = <Date 2018-12-26.00:26:24.805>
    creator = 'asvetlov'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35585
    keywords = ['patch', 'patch']
    message_count = 3.0
    messages = ['332524', '332558', '332562']
    nosy_count = 2.0
    nosy_names = ['asvetlov', 'ethan.furman']
    pr_nums = ['11318', '11318', '11324']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue35585'
    versions = ['Python 3.7', 'Python 3.8']

    @asvetlov
    Copy link
    Contributor Author

    Construction enums by-value (e.g. http.HTTPStatus(200)) performs two dict lookups:
    if value in cls._value2member_map_:
    return cls._value2member_map_[value]

    Changing the code to just
    return cls._value2member_map_[value]
    with catching KeyError can speedup the fast path a little.

    @asvetlov asvetlov added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir labels Dec 26, 2018
    @ethanfurman
    Copy link
    Member

    New changeset 34ae04f by Ethan Furman (Andrew Svetlov) in branch 'master':
    Speed-up building enums by value, e.g. http.HTTPStatus(200) (bpo-11318)
    34ae04f

    @asvetlov
    Copy link
    Contributor Author

    New changeset 705b599 by Andrew Svetlov (Miss Islington (bot)) in branch '3.7':
    Speed-up building enums by value, e.g. http.HTTPStatus(200) (GH-11318) (GH-11324)
    705b599

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants