more useful options | |
PerlMonks |
Re: Memory overhead of blessed hashesby ForgotPasswordAgain (Priest) |
on Feb 09, 2021 at 17:04 UTC ( [id://11128136]=note: print w/replies, xml ) | Need Help?? |
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. :)
In Section
Seekers of Perl Wisdom
|
|