Re: REQ: High Performance Access to a Static Object's List<string>
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Tue, 11 Sep 2007 22:40:09 -0700
Mark S. wrote:
How would that make it any less efficient?
If it's a reference then why create a new list? I'd simply loop over the static object's list directly.
Well, one reason to copy to a local variable would be so that the static object's reference could be updated by one thread without affecting the instance being used by another.
This would assume that the list instances themselves are immutable, as I suggested in my other reply.
If changes to the list are always in place then, yes...you'll need to synchronize access to the list so that, at a minimum, writing to the list only occurs when no other thread is also trying to read from it.
Easier would be to synchronize all access to the list, but then even readers of the list would wind up serialized, which could hinder performance. It's a classic trade-off...easy and optimal are not always the same. :)
Maximum concurrency is what I'm striving for. If only N number of requests can read the static object's list then I was wondering if making a copy of the list would more quickly release the read to be used by another request.
To some extent, that depends on what you're doing during the read. If each element of the list requires extensive time to process during the iteration then it's possible copying the list could speed things up. However, you may still have synchronization issues between individual list elements if you do a shallow copy, or you may not find there's any significant performance benefit if you do a deep copy.
Otherwise that read hold stays in effect during the loop. Which then begs question, does the creating the copy consume more the CPU thereby negating any gains.
Only by measuring it will you know for sure. It all depends on how expensive a deep copy is, whether you even need a deep copy, and how much work the actual use of the list involves.
Personally, I'd go for the immutable list design, but then that's probably already apparent since I mentioned it twice already. :) I think that, at the very least, copying the list each time it changes (which would be required if the list instance itself is immutable) is likely to be much more efficient than copying it each time you actually use it.
Pete
.
- References:
- REQ: High Performance Access to a Static Object's List<string>
- From: Mark S.
- Re: REQ: High Performance Access to a Static Object's List<string>
- From: Marc Gravell
- Re: REQ: High Performance Access to a Static Object's List<string>
- From: Mark S.
- REQ: High Performance Access to a Static Object's List<string>
- Prev by Date: Re: REQ: High Performance Access to a Static Object's List<string>
- Next by Date: Setting control to dock fill when you have a menustrip
- Previous by thread: Re: REQ: High Performance Access to a Static Object's List<string>
- Next by thread: Re: REQ: High Performance Access to a Static Object's List<string>
- Index(es):
Relevant Pages
|