Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Just another Perl shrine
 
PerlMonks  

Re^4: Could we save the memory occupied by "undef" in an array?

by TimToady (Parson)
on Nov 24, 2008 at 17:30 UTC ( #725649=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Could we save the memory occupied by "undef" in an array?
in thread Could we save the memory occupied by "undef" in an array?

Your program is already heavily invested in the performance of hashes. Most objects use hashes as their underlying data structure. Every reference to a package variable results in multiple hash lookups (I think). And every call to a subroutine results in multiple hash lookups (I think).
Well, then, think again. :)

To the first approximation, only packages use hashes for their internal structure, and most package symbol lookups happen only at compile time. (Any stored GV* is post-hash-lookup.) Apart from symbolic references (which are discouraged), the only major operation that historically used hash lookups implicitly at run time was method calls, and I think even that has been heavily optimized these days when the method name is known in advance.

There are other implicit uses of hashes, but these typically come into play only when you start using higher Unicodes characters in patterns, and even there the internals typically try to avoid using the hash in the common cases.

In any event, normal sub calls don't use any implicit hashes. They're already too slow as it is...


Comment on Re^4: Could we save the memory occupied by "undef" in an array?
Download Code
Re^5: Could we save the memory occupied by "undef" in an array?
by ikegami (Pope) on Nov 24, 2008 at 18:26 UTC
    Thanks for the correction. I can't figure out what lead me to think function lookups were made at run-time.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2014-04-18 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls