Feature Requests item #1589074, was opened at 2006-11-02 00:55
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1589074&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
>Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Daniel (kamek)
Assigned to: Nobody/Anonymous (nobody)
Summary: Unneeded constants left during optimization

Initial Comment:
At some point, when generating the bytecode, the
parser/compiler pre-calculates operations on constants.
However, the old values, which are often not needed
anymore in the constants, are left there as garbage.

To keep this description from being lengthy, I'm
attaching a text file with several simple
demonstrations that serve as testcases.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2006-11-05 15:39

Message:
Logged In: YES 
user_id=80475

I looked at this when constant folding was first introduced
and it did not seem worth doing because 1) it would be
somewhat complicated to implement (counting each time a
constant is used and renumbering all constant references
once a deletion occurs), 2) it would be hard to maintain, 3)
it would slow-down compilation, and 4) the potential benefit
is microscopic (saving a few bytes but not improving
execution speed).

Here's an example of the difficulty:

>>> def f():
        x = 3
        y = 3 + 4
        return x + y

>>> f.func_code.co_consts
(None, 3, 4, 7)

The constant folding for 3+4 introduces the 7 but cannot
easily know that the 3 is used elsewhere while the 4 is not.

Am reclassifying this as a feature request for a trivial
space optimization (there is no bug, the peepholer is
functioning as designed). This suggestion could be
implemented but (IMO) is not worth it.



----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2006-11-04 10:29

Message:
Logged In: YES 
user_id=21627

Would you like to work on a patch to fix this problem?

----------------------------------------------------------------------

Comment By: Daniel (kamek)
Date: 2006-11-02 00:58

Message:
Logged In: YES 
user_id=539453

Sorry, I rushed and missed the File Description field.
Should be "Interactive interpreter testcases".

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1589074&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to