Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: "exists $hash{key}" is slower than "$hash{key}"

by LanX (Saint)
on Jan 06, 2020 at 01:18 UTC ( [id://11111020]=note: print w/replies, xml ) Need Help??


in reply to Re^2: "exists $hash{key}" is slower than "$hash{key}"
in thread "exists $hash{key}" is slower than "$hash{key}"

> If this is the case then it seems counter intuitive at first glance, and maybe is something that could be modified.

Well - "if this is the case" - it's most probably for "historical reasons".

I could imagine exists came later and that was the easiest way to implement it, and the pay off for any redesign is too small.

You shouldn't forget that there is much more going on in the background which would need to be replicated, like autovivification and so on.

> One advantage of using exists

I'm not sure I can follow.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Comment on Re^3: "exists $hash{key}" is slower than "$hash{key}"

Replies are listed 'Best First'.
Re^4: "exists $hash{key}" is slower than "$hash{key}"
by swl (Parson) on Jan 07, 2020 at 00:52 UTC

    Yes, I assume the code is written this way for good historical reasons. These reasons might no longer apply or be out-weighed by other factors, but I don't know enough to be able to say if any change would be worthwhile.

    The advantage of exists over checking values is tangential to the main point of the post. It's about memory usage - if one re-uses the same SV across hash values then that takes less memory than using a new SV for each hash value. It's another case where one needs a very large number of hash entries for it to make a meaningful difference, but there are times when this applies.

      > It's about memory usage

      I can't say much about this, ...

      ... but my gut feeling is that this is a kind of micro optimization, which's efforts should rather spent else where.

      Otherwise you should talk to p5p ...

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        Yes, it is most definitely a micro-optimisation. This is consistent with the last two paras in my original post, although I did not explicitly use that term there.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found