On Mon, 2005-12-12 at 16:44 -0500, Uri Guttman wrote:
> >>>>> "DL" == Donald Leslie {74279} <[EMAIL PROTECTED]> writes:
>
> DL> I have an apache/mod-perl application that can results in large
> DL> xml strings which are then transformed by xslt into html. A
> DL> database query can result in an xml string with a length greater
> DL> than 300,000 . In a normal perl allocation you can pre-extend the
> DL> string to prevent repeated new allocations and copies. Does anyone
> DL> know what happens in a mod-perl application? Does pre-extending
> DL> have any benefit?
>
> i can't tell you about any mod-perl issues but in general pre-extending
> in perl doesn't gain you as much as you would think. the reason is that
> some storage isn't really truely freed to the main pool when it gets
> freed when its ref count goes to 0. perl will keep it around in
> anticipation of it be reallocated for this same item in a future call or
> loop iteration. so it is effectively doing the usual doubling its size
> to grow into the first large string and then it is already prextended
> the rest of the time via reusing the previous buffer.
Well, just in one trial, it does look like the data gets moved with
every substantial growth.
$ time perl -le '$s = ""; foreach
(1,10,1000,10_000,100_000,1_000_0000,100_000_000,1_000_000_000){ $s .= "1" x
$_;loc($s)} sub loc { print "Len: ", length($_[0]), "; Location: ",unpack "I",
pack "p", $_[0] }'
Len: 1; Location: 167281112
Len: 11; Location: 167281112
Len: 1011; Location: 167310280
Len: 11011; Location: 167329304
Len: 111011; Location: 167440328
Len: 10111011; Location: 3066564616
Len: 110111011; Location: 2856448008
Len: 1110111011; Location: 746332168
real 0m5.028s
user 0m1.928s
sys 0m3.069s
WARNING: running the above might freeze or crash your system or some
applications by running you out of memory. Gigabyte reallocs are ...
interesting. Season to taste.
> and on a final note, these days 300k is not even a long string.
But it IS a fairly large amount of XML, given how expensive XML parsing
can be (sigh). It's especially painful because this 300k of XML is XSLT,
which means that he's planning on reading / interpreting / transforming
all 300k.
--
Aaron Sherman <[EMAIL PROTECTED]>
Senior Systems Engineer and Toolsmith
"We had some good machines, but they don't work no more." -Shriekback
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm