Wow, that really is something. When I read your first email, my initial
response was "enums are ints - of course they won't be getting boxed".
Now I'm off to check my code to find out how many of these I'm using :)
Roger Kratz wrote:
That you'll better ask the dictionary implementors at Redmond J. I was
a bit surprised by this myself some time ago. Just create a little
test yourself and probably you will be more than surprised by the
result...
There are some articles out there describing it better than I probably
can...
http://www.safnet.com/writing/tech/archives/2007/07/performance_3_c.html
http://blogs.msdn.com/shawnhar/archive/2007/07/02/twin-paths-to-garbage-collector-nirvana.aspx
http://beardseye.blogspot.com/2007/08/nuts-enum-conundrum.html
*From:* [email protected]
[mailto:[email protected]] *On Behalf Of *Ayende
Rahien
*Sent:* den 6 februari 2009 15:45
*To:* [email protected]
*Subject:* [nhibernate-development] Re: IDictionary<entitymode, xxx>
Ha?
Why would there be boxing involved at all?
On Fri, Feb 6, 2009 at 3:46 PM, Roger <[email protected]
<mailto:[email protected]>> wrote:
Hi
EntityModeToTuplizerMapping holds a dic keyed by entitymode
internally. From a perf perspective, it's a bad thing to do -- enum as
a key will cause a lot of boxing internally in dictionary operations.
And in (large) resultsets these dictionary items in it will be
retrieved _a lot_.
I just made a quick test and changed this dictionary to be keyed by an
int instead (casting the enum to int when added), some extreme queries
(=fast query, big resultset) run approx 10% faster in total.
I'll be glad to send this little patch. However, I would say a better
solution would be to change this enum to a class instead (I don't
really like enums at all :)). I can provide a patch for this as well,
but this type has a lot of dependencies. In short words -- before
spending some hours doing this, I would like to see if you have any
opinions on this?
Whatever you think, I would strongly suggest that get rid of often
used dictionaries keyed by enums.
Keep up the great work!
Regards
Roger