in reply to Re^2: Perl Objects, Internal Representation -- How??
in thread Perl Objects, Internal Representation -- How??

"Why" is simple and should be obvious

You think?

I am looking to optimize it and improve its efficiency in terms of both memory and execution speed.

In general, Perl tends to trade memory for speed, so how to optimise for both is rarely obvious and never easy.

But there are times that I wish it had a mechanism to permit hard-typing and struct-based objects.

Using a scalar-ref based object implementation, where the referenced string is a pack'd representation of the data can reduce memory consumption by 90% or so.

For example, a typical log file line might contain a couple of ip address/port numbers; a datetime stamp; a protocol string; a process name and another couple of short text fields. Stored as hash-based objects, each field named and the string stored as the value, 1e6 objects consumes ~1GB of ram.

The same data pack'd to a single string, and it's reference blessed, the storage requirement drops to < 100MB.

But, you pay a penalty for unpacking the data when accessing it. Done right, the penalty doesn't have to be huge, but there is a penalty. Nothing's for free.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^3: Perl Objects, Internal Representation -- How??