http://qs321.pair.com?node_id=216529


in reply to Dprof and main::BEGIN

I am seeing that the majority of time (40% or more) is being taken up with many thousands of calls to main::BEGIN.
The answer can be found in a recent p5p post by Tim Bunce
A BEGIN block gets a CV, executes, the CV is freed and another sub is created with the same CV address. The result is that Devel::DProf (for example) will report BEGIN blocks being called many times when in fact it's a different sub. Very frustrating.
The initial p5p thread starts here.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Dprof and main::BEGIN
by dbush (Deacon) on Nov 29, 2002 at 15:48 UTC

    broquaint many thanks for your response.

    From the sounds of things, this effect is unavoidable. Just to clarify my understanding, is a CV an internal data structure? I seem to remember reading something in perlman:perlguts about two letter typedefs before I was scared away.

    Regards,
    Dom.

      Just to clarify my understanding, is a CV an internal data structure?
      A CV is an internal representation of a subroutine (see. Code Value). It's a typedef of a struct cv which has a pointer to a XPVCV which is a typedef for a struct xpvcv which can be found in cv.h in the perl source code. Simple as that ;)
      HTH

      _________
      broquaint

        Many thanks to broquaint and Elian for their answers. ++ to you both. I had a brief look at cv.h but the fear overcame me again.

        Regards,
        Dom

      CV is short for Code Value, and is one of perl's internal data types. (It's a sub-class of SV, the Scalar Value, if you can think of purely C code as subclassing anything :)