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

Control flow not optimized #47525

Closed
quotemstr mannequin opened this issue Jul 3, 2008 · 3 comments
Closed

Control flow not optimized #47525

quotemstr mannequin opened this issue Jul 3, 2008 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@quotemstr
Copy link
Mannequin

quotemstr mannequin commented Jul 3, 2008

BPO 3275
Nosy @birkenfeld, @benjaminp

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 2008-07-03.20:51:29.437>
created_at = <Date 2008-07-03.20:43:13.035>
labels = ['interpreter-core', 'performance']
title = 'Control flow not optimized'
updated_at = <Date 2008-07-04.09:05:53.312>
user = 'https://bugs.python.org/quotemstr'

bugs.python.org fields:

activity = <Date 2008-07-04.09:05:53.312>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = <Date 2008-07-03.20:51:29.437>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2008-07-03.20:43:13.035>
creator = 'quotemstr'
dependencies = []
files = []
hgrepos = []
issue_num = 3275
keywords = []
message_count = 3.0
messages = ['69230', '69231', '69248']
nosy_count = 3.0
nosy_names = ['georg.brandl', 'benjamin.peterson', 'quotemstr']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'performance'
url = 'https://bugs.python.org/issue3275'
versions = ['Python 2.5']

@quotemstr
Copy link
Mannequin Author

quotemstr mannequin commented Jul 3, 2008

Consider:

import dis
def foo():
  if 0 and 1: return "hi"

dis.dis(foo)

What I get is

2 0 LOAD_CONST 1 (0)
3 JUMP_IF_FALSE 15 (to 21)
6 POP_TOP
7 LOAD_CONST 2 (1)
10 JUMP_IF_FALSE 8 (to 21)
13 POP_TOP
14 LOAD_CONST 3 ('hi')
17 RETURN_VALUE
18 JUMP_FORWARD 1 (to 22)
>> 21 POP_TOP
>> 22 LOAD_CONST 0 (None)
25 RETURN_VALUE

What I'd expect to see is:

1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE

@quotemstr quotemstr mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage labels Jul 3, 2008
@benjaminp
Copy link
Contributor

A patch for this was just recently rejected. See bpo-1394.

@birkenfeld
Copy link
Member

What real-life use case do you have for a condition that is a boolean
operation on two constant values anyway? Things like

while 1:
   ...

are properly optimized since they serve a useful purpose.

@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
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
Projects
None yet
Development

No branches or pull requests

2 participants