classification
Title: Speedup Enum lookup
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: asvetlov, ethan.furman
Priority: normal Keywords: patch, patch

Created on 2018-12-26 00:26 by asvetlov, last changed 2018-12-26 20:52 by asvetlov. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11318 merged asvetlov, 2018-12-26 00:29
PR 11318 merged asvetlov, 2018-12-26 00:29
PR 11324 merged miss-islington, 2018-12-26 18:46
Messages (3)
msg332524 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2018-12-26 00:26
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.
msg332558 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-12-26 18:45
New changeset 34ae04f74dcf4ac97d07c3e82eaf8f619d80cedb by Ethan Furman (Andrew Svetlov) in branch 'master':
Speed-up building enums by value, e.g. http.HTTPStatus(200) (#11318)
https://github.com/python/cpython/commit/34ae04f74dcf4ac97d07c3e82eaf8f619d80cedb
msg332562 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2018-12-26 20:48
New changeset 705b5998035739b1794a862123d3dc6e339a14d0 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)
https://github.com/python/cpython/commit/705b5998035739b1794a862123d3dc6e339a14d0
History
Date User Action Args
2018-12-26 20:52:32asvetlovsetkeywords: patch, patch
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-12-26 20:48:58asvetlovsetmessages: + msg332562
2018-12-26 18:46:02miss-islingtonsetpull_requests: + pull_request10587
2018-12-26 18:45:38ethan.furmansetmessages: + msg332558
2018-12-26 01:23:47rhettingersetkeywords: patch, patch
assignee: ethan.furman

nosy: + ethan.furman
2018-12-26 00:29:57asvetlovsetkeywords: + patch
stage: patch review
pull_requests: + pull_request10569
2018-12-26 00:29:55asvetlovsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request10568
2018-12-26 00:26:24asvetlovcreate