On Sun, 05 Oct 2008 12:44:09 -0700,
je**********@gmail.com
<je**********@gmail.comwrote:
Hello:
I am experiencing performance related issues when my custom data
structures work with value types. I use generics to prevent boxing
wherever I can. For instance, I use IEqualityComparer, etc. I have
gone through most of my data structures and verified that I don't
compare to null or call methods that would box my value types.
However, I am still experiencing performance problems. I can process
strings faster than I can process integers, which seems a little
backwards. I feel like I am overlooking some boxing taking place, but
I can't think where it could be. Could someone please clue me in to
additional things to keep an eyes open for? It would be really awesome
to eliminate any unforeseen bottlenecks.
As in the previous thread, impossible to answer without seeing your code.
There are all sorts of tradeoffs with respect to value types versus
reference types. Certain kinds of operations with value types can be more
expensive, especially if they are relatively large and wind up copied a
lot. On the other hand, a value type can provide better semantics,
especially if they are small and immutable. Of course, whether you
declare a data structure as a struct or a class, if it's used in an
inappropriate way or the code has some fundamental architectural flaw,
that will likely hide whatever performance difference might be apparent
due simply to the kind of data type used.
If the _only_ difference between your test cases is that in one a string
is used and in the other an int is used, then sure...that does sound like
you might have some boxing going on in the int case. But without a code
example, it's impossible to say for sure whether that's what's going on,
never mind in what way. And if there are any other differences in the
test cases, then all bets are off. It could be boxing, or it could be
something completely different.
If you are unwilling to post code examples, you might as well stop asking
these kinds of questions. No one can answer questions about how your code
works without seeing the code. Write a concise-but-complete code sample
that demonstrates the performance difference you're seeing, and post it
here. Only then can someone else take a look at it and explain the
performance difference.
Pete