[New-bugs-announce] [issue2181] optimize out local variables at end of function

Neal Norwitz report at bugs.python.org
Mon Feb 25 03:00:14 CET 2008

New submission from Neal Norwitz:

This patch optimizes code like:

   x = any_expression
   return x

   return any_expression

Currently it only optimizes out the local variable if there is a return
because it can't determine if this is the last use of the variable or not.

This shouldn't change behaviour under normal circumstances, but would
change behaviour with a debugger.  Perhaps this optimization should only
be performed if -O is passed on the command line?

This optimization saves two trips around the eval loop (STORE_FAST and
LOAD_FAST) and 6 bytes in the byte code.

components: Interpreter Core
files: opt-out-local-var.patch
keywords: patch, patch
messages: 62957
nosy: nnorwitz
severity: normal
status: open
title: optimize out local variables at end of function
type: resource usage
Added file: http://bugs.python.org/file9544/opt-out-local-var.patch

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list