This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Optimizing constant comparisons/contains
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, Crowthebird, pablogsal, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-11-19 14:06 by Crowthebird, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29639 closed Crowthebird, 2021-11-19 14:07
Messages (5)
msg406582 - (view) Author: Jeremiah Gabriel Pascual (Crowthebird) * Date: 2021-11-19 14:06
Result of `255581293 > 12938373 and 113314 < 2`:
Unoptimized: 5000000 loops, best of 5: 42.6 nsec per loop
Optimized: 20000000 loops, best of 5: 14.4 nsec per loop
msg406583 - (view) Author: Jeremiah Gabriel Pascual (Crowthebird) * Date: 2021-11-19 14:09
Above tested using `timeit.main`.
msg406688 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2021-11-20 20:18
> Result of `255581293 > 12938373 and 113314 < 2`:

Is there a similar pattern that happens a lot on the client code? The AST optimizer currently only optimizes common cases.
msg406705 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-11-21 10:09
Why anybody needs to write 255581293 > 12938373?

We try to keep the compiler code maintenable and only implement optimizations which have the largest effect. PR 29639 adds around 200 lines of complex code and I do not see the benefit.
msg406723 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-11-21 15:25
I agree with Serhiy
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 90001
2021-11-22 20:02:54serhiy.storchakasetstatus: open -> closed
resolution: rejected
stage: patch review -> resolved
2021-11-22 15:04:20Crowthebirdsettitle: Optimizing LOAD_CONST followed by COMPARE_OP (or IS_OP) -> Optimizing constant comparisons/contains
2021-11-21 15:29:44AlexWaygoodsettype: performance
2021-11-21 15:25:40pablogsalsetmessages: + msg406723
2021-11-21 10:09:40serhiy.storchakasetmessages: + msg406705
2021-11-20 20:18:57BTaskayasetnosy: + BTaskaya, pablogsal, serhiy.storchaka
messages: + msg406688
2021-11-19 14:09:12Crowthebirdsetmessages: + msg406583
2021-11-19 14:07:28Crowthebirdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request27870
2021-11-19 14:06:30Crowthebirdcreate