6.4. Scatchpads and Targets

PP code is the guts of Perl execution, and hence is highly optimized for speed. One thing that you don't want to do in time-critical areas is create and destroy SVs, because allocating and freeing memory is a slow process. So Perl allocates for each op a target SV which is created at compile time. We've seen above that PP code gets the target and uses the PUSH macros to push the target onto the stack.

Targets live on the scratchpad, just like lexical variables. op_targ for an op is an offset in the current pad; it is the element number in the pad's array which stores the SV that should be used as the target. Perl arranges that ops can reuse the same target if they are not going to collide on the stack; similarly, it also directly uses lexical variables on the pad as targets if appropriate instead of going through a padsv operation to extract them. (This is a standard compiler technique called "binding".)

You can tell if an SV is a target by its flags: targets (also known as temporaries) have the TEMP flag set, and SVs bound to lexical variables on the pad have the PADMY flag set.