Dan Sugalski <[EMAIL PROTECTED]> writes:
> True enough. This is a small subset of general optimizations. For example,
> this:
> 
> 
>    $i = 0;
>    foreach (1..1000) {
>     $i++;
>    }
> 
> can be easily optimized to:
> 
>    $i = 1000;
> 
> and most language implementations with any sort of optimizer will do this. If
> $i isn't actually used after that point without another assignment it might
> well be completely optimized away. With perl, though, this does potentially
> unexpected things if $i is tied. Do we still optimize it away? Do we only do
> it if we can tell that $i's not tied? Do we force the programmer to explicitly
> note which variables are potentially tied with the "my Dog $spot" syntax and
> assume that everything else is fair game? Can we even do that in the face of
> runtime requires, dos, or evals? (Or does that force a complete reevaluation
> of the optimized bytecode)

How painful would an 'potential' optimization that marked that area in
the bytecode/optree/whatever, with something along the lines of the
following be?

    If you get to this point and $i is not tied, and '=' is not
    overridden for $i's class 
    then $i = 1000
    otherwise, do the loop.

Of course, it means that the static runtime size is going to increase,
but presumably these potential optimizations wouldn't get done in the
presence of 'use less qw/space/'

-- 
Piers

Reply via email to