Devel::Size is a very useful module for working out where your memory is being consumed, but it has one major caveat. In the process of determining the size of complex structures, itself consumes prodigious amounts of memory.

Most of that is consumed tracking references to a) prevent recursing endlessly around circular data structures; b) to avoid counting the same substructures multiple times. As all D::S requires is a boolean answer as to whether a given address has been seen (and counted) before, using a hash is a convenient but costly way to do it.

I've switch that to using a (segmented) bitstring, with the result that the following one-liners require a tiny fraction of additional memory for D::S to do it's thing, relative to the current cpan version, as demonstrated by the following one-liners:

c:\test>perl -MDevel::Size=total_size -lwe "$h{ $_ } = [1 .. $_] for 1 .. 1e3;scalar<>;print total_size( \%h ); s +calar <>;" 11,196k 10115049 46,260k c:\test>perl -MDevel::Size=total_size -lwe "$h{ $_ } = [1 .. $_] for 1 .. 1e3;scalar<>;print total_size( \%h ); s +calar <>;" 11,196k 10115049 11,240k c:\test>perl -MDevel::Size=total_size -lwe "$h{ $_ } = [1 .. $_] for 1 .. 5e3;scalar<>;print total_size( \%h ); s +calar <>;" 253,664k 250591721 1,147,000 c:\test>perl -MDevel::Size=total_size -lwe "$h{ $_ } = [1 .. $_] for 1 .. 5e3;scalar<>;print total_size( \%h ); s +calar <>;" 253,644k 250591721 253,776k

The 3 numbers below each run are: 1) The memory consumed by the process prior to sizing it; 2) the size of that structure as evaluated by D::S; 3) the memory consumed by the process after D::S::total_size() runs. The different between the first and third figures is the overhead of the tracking mechanism.

The first set of figures in each pair are those for the cpan version 0.71; the second for my modified version (dubbed 0.71x for now)

As you can, in these tests, rather than incurring an overhead of ~4 times the requirement of the data-structure being measured, it is just a couple of hundred KB in both cases.

This post is to ask for testers on other (non-win32; 32-bit only currently*) platforms that think they have existing testcases that will exercise this well, to email me at vev6s4702 sneakemail.com (complete) and I'll send them a new distribution (30k) for testing.

(*)I hope to extend that to 64-bit too, but will need the cooperation of someone with a (preferably win64) suitable platform.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to X-platform testers wanted: new version of Devel::Size by BrowserUk

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.