So - is there any way at all to reduce the overhead of these arrays that doesn't involve pack and unpack

Why exclude solutions that involve pack and unpack?

C:\test>p1 $x = ['20110106', map( rand( 1e5 ), 1..4 ), int( rand 1000 ) ];; print total_size $x;; 440 print for @$x;; 20110106 4663.0859375 274.658203125 53915.4052734375 11352.5390625 145

Using join & split (72% saving):

$y = join $;, @$x;; print total_size $y;; 120 print for split $;, $y;; 20110106 4663.0859375 274.658203125 53915.4052734375 11352.5390625 145

Using pack & unpack (78% saving):

$z = pack 'c/A* d4 n', @$x;; print total_size $z;; 96 print for unpack 'C/A* d4 n', $z;; 20110106 4663.0859375 274.658203125 53915.4052734375 11352.5390625 145

Of course, there is some performance penalty for spliting or unpacking the arrays when thay are used, but it's not onerous:

#! perl -slw use strict; use Devel::Size qw[ total_size ]; use Benchmark qw[ cmpthese ]; my @AoA = map[ '20110106', map( rand( 1e5), 1..4 ), int( rand 1000 ) ], 1 .. 1e5; my @AoS = map{ join $;, @$_; } @AoA; my @AoP = map{ pack 'C/A* d4 i', @$_; } @AoA; print 'AoA: ', total_size \@AoA; print 'AoS: ', total_size \@AoS; print 'AoP: ', total_size \@AoP; cmpthese 10, { AoA => sub { my $sum; for my $i ( 0 .. $#AoA ) { $sum += $AoA[ $i ][ $_ ] for 1 .. 5; } # print $sum; }, AoS => sub { my $sum; for my $i ( 0 .. $#AoS ) { my @a = split $;, $AoS[ $i ]; $sum += $a[ $_ ] for 1 .. 5; } # print $sum; }, AoP => sub { my $sum; for my $i ( 0 .. $#AoP ) { my @a = unpack 'C/A* d4 i', $AoP[ $i ]; $sum += $a[ $_ ] for 1 .. 5; } # print $sum; }, }; __END__ C:\test>880868 AoA: 70400176 AoS: 13549296 80% saving AoP: 10400176 85% saving Rate AoS AoP AoA AoS 0.977/s -- -52% -78% AoP 2.05/s 110% -- -53% AoA 4.39/s 349% 114% --

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.

In reply to Re: bit by overhead by BrowserUk
in thread bit by overhead by Anonymous Monk

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.