From: Eivind Eklund Date: 2007-12-12T16:29:52+09:00 Subject: Re: Dynamically generate a symbol name On Dec 11, 2007 4:45 PM, Gary Wright wrote: > On Dec 11, 2007, at 7:00 AM, Sam Smoot wrote: > > > > :"object#{n}" is the syntax. Or just "object#{n}".to_sym. > > > > I would avoid doing this though. Symbols aren't meant to represent > > infinite variations. They're stored in a Hash internally, so the more > > symbols you add, the slower they get. > > Hash table performance shouldn't be affected by size, that is the > whole point of using a hash table. The memory footprint will increase. Unless you're already past the limit where each cache line on average only contains one accessed symbol, this memory footprint increase will decrease cache locality which again will decrease performance. In the general case: Depending on hash table implementation, you could also have chaining costs as your hash table grows to be full (which gives conflicts that need either chaining, a tree, or a rebuild of the table to handle). "Hash table performance is not affected by size" is a simplification that hold when you have a pre-90s microprocessor or a microcontroller and the entire hash table is in memory to start with and you have no two entries that hash to the same slot. This is a restricted case. Assuming some speed loss for increased size is a good assumption. As for the point of a hash table, I tend to think of it as "Fast access to data where the ordering property don't matter" (or lookup is convenient on something that isn't a number). Eivind.