Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Memory overhead of blessed hashes

by ForgotPasswordAgain (Priest)
on Feb 09, 2021 at 17:04 UTC ( [id://11128136]=note: print w/replies, xml ) Need Help??


in reply to Memory overhead of blessed hashes

I'm not sure exactly what your situation is, so a lot of this is probably irrelevant:

In my experience, using objects versus unblessed hashes can cause things to be slower (CPU overhead of blessing them) but doesn't add much memory overhead.

In some situations it might make more sense (financially) to add more RAM instead of spending time reworking the code.

It's probably not relevant here if you're using objects normally, but with deeply-nested hashes (when doing aggregation, for example) you can save a bit of memory by flattening the hash and concatenating the keys with $;.

If you're pulling data from a database, keeping the data "on the C side" can save a lot of memory. At least by default with DBD::mysql, it will download the data all at once into C structures, which uses a lot less memory than the same data "inflated" into Perl structures. So for example when aggregating (sum, avg, ...), if you can fetch individual rows instead of all at once, it can save memory. Depending on how (elegant, simple) your code is, it can be challenging to refactor it to do this, though.

End of memory dump. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11128136]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found