in reply to Variable declaration optimization?

The cost of lexical variable declaration occurs solely during compilation time, and there are better ways to improve compilation time (trimming @INC, for example) if that's a problem (and it's rarely a problem).

Replies are listed 'Best First'.
Re^2: Variable declaration optimization?
by LanX (Saint) on Oct 13, 2010 at 02:16 UTC
    > The cost of lexical variable declaration occurs solely during compilation time

    IMHO "solely" is wrong, for instance lexicals are initialized to undef and if you check the reference of a variable declared in the head of a loop you can observe that they can change, i.e. there is no singular allocation overhead at compile time.

    Furthermore there is an opcode executed at runtime for this (see line3)

    perl -MO=Concise -e 'my $a;$a=1' 8 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 3 <0> padsv[$a:1,2] vM/LVINTRO ->4 4 <;> nextstate(main 2 -e:1) v:{ ->5 7 <2> sassign vKS/2 ->8 5 <$> const[IV 1] s ->6 6 <0> padsv[$a:1,2] sRM* ->7

    Anyway this is one of the last places I would consider for optimizations.

    Cheers Rolf

      I had meant parsing time, but you're right; I hadn't realized there exists an optimization for declare-and-assign.