View Single Post
03-30-09, 08:06 PM   #19
watchout
A Fallenroot Satyr
Join Date: Mar 2008
Posts: 20
Originally Posted by Foxlit View Post
The number of entires in the global environment has nothing to do with this. There's generally no difference in access time between "large" and "small" hash tables -- the number of buckets is simply increased when more entires are added, which is a one-time cost when the table is rehashed. The entire "overpopulated table" line of reasoning is invalid.
Somehow I'd hoped such an answer would come... though I thought the part about meta-tables would cause more replies.

Yes, size does matter
O(1) (for lookup) is only average case for your typical hash table implementation, and that only if the key-hashes follow the perfect distribution that the hash-function designer thought to be universal. Worst case is O(n). Reality will be somewhere in between, especially since best case O(1) = average case O(1) should give you a hint on why the O-notation is not always the perfect method to judge the performance of an algorithm.

Originally Posted by Foxlit View Post
The performance difference you observe is caused by only looking up "sometableinglobal" once, rather than every time you access it. This applies to *all* nested tables: if you're performing a large number of operations on some sub-table, use a local reference rather than looking it up in its parent table every time.
This however... is wrong. In the specific way that you did not correctly guess what performance difference I observed. The performance difference you mean is because global variables are stored in a hashtable, while locals are stored / used in the registers. True. I definitely don't object to that, but that's too obvious.
I was telling from old data, the difference used to be much bigger back in 2.x. I reran my bench when writing this post and found that the performance of the global table has significantly improved (it's still not completely the same as an empty table though, about 2-5% off *cough*), I apologize for this. I just should have rerun the bench when writing my previous post.



@Aezay:
It used to be much bigger - so big actually that my client locked up and disconnected before finishing counting. After that I stopped trying... I think I read something about blizzard removing global variables in some patch notes though.
Your count is one off btw. you need to start at zero
  Reply With Quote