Some of the extra space may be down to unreused (but reusable) space allocated and freed during the doubling of the STASH hash as it grows.

Devel::Peek shows that stash entries created by coderef assignment to a GLOB are missing the MAGIC part of a GV:

use Devel::Peek; sub foo { print "in foo\n"; } *bar = \&foo; print "----\nfoo:\n----\n"; Dump(*foo); print "----\nbar\n----\n"; Dump(*bar); __END__ ---- foo: ---- SV = PVGV(0x1765790) at 0x1731550 REFCNT = 3 FLAGS = (RMG,MULTI,IN_PAD) MAGIC = 0x1732e80 MG_VIRTUAL = &PL_vtbl_backref MG_TYPE = PERL_MAGIC_backref(<) MG_OBJ = 0x1725238 NAME = "foo" NAMELEN = 3 GvSTASH = 0x1705800 "main" GP = 0x1732870 SV = 0x0 REFCNT = 1 IO = 0x0 FORM = 0x0 AV = 0x0 HV = 0x0 CV = 0x1725238 CVGEN = 0x0 LINE = 4 FILE = "f.pl" FLAGS = 0xa EGV = 0x1731550 "foo" ---- bar ---- SV = PVGV(0x17657c0) at 0x1725208 REFCNT = 3 FLAGS = (MULTI,ASSUMECV,IN_PAD) NAME = "bar" NAMELEN = 3 GvSTASH = 0x1705800 "main" GP = 0x1759a40 SV = 0x0 REFCNT = 1 IO = 0x0 FORM = 0x0 AV = 0x0 HV = 0x0 CV = 0x1725238 CVGEN = 0x0 LINE = 5 FILE = "f.pl" FLAGS = 0xe EGV = 0x1725208 "bar"

I don't think the sizes reported by Devel::Size are accurate since the stash entry created by coderef assignment is reported as being bigger.
Go figure.

use Devel::Size qw(size total_size); sub foo { print "in foo\n"; } print "size foo: ",size(*foo),"\n"; print "total_size foo: ",total_size(*foo),"\n"; print "size bar: ",size(*bar),"\n"; print "total_size bar: ",total_size(*bar),"\n"; print "difference: ",size(*foo) - size(*bar),"\n"; __END__ size foo: 7034 total_size foo: 7034 size bar: 7186 total_size bar: 7186 difference: -152
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re^3: Memory efficiency, anonymous vs named's vs local subroutines by shmem
in thread Memory efficiency, anonymous vs named's vs local subroutines by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.