in reply to Re^2: Memory efficiency, anonymous vs named's vs local subroutines
in thread Memory efficiency, anonymous vs named's vs local subroutines
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
|
|---|