0

I have a rather large program and as such just going to simplify a bit.

So I have a List (Of Entity), Entity being a custom class with heaps of properties. I have a 1ms timer, which constantly updates this list. In the timer it creates a temporary list from the external source, and if that list is different to the current list, updates the main list.

Now this is where it gets slow, I think. I have A LOT of threads, one for each property of the class which constantly updates that property (the values come externally) and I stop them all, otherwise whilst the list gets updated it will throw all kinds of errors. Then I update the main list with the temp list, and then create new threads again e.g.

Prop1Thread = New Thread(AddressOf UpdateProp1)

and start them all again.

Pretty much is there a better method I could use? The properties have to be updated in different threads, otherwise it destroys performance. I can't change the way I get the list of entities either. I just really need a better way of handling the updating of the properties of the changing list of Entities.

4

1 回答 1

2

Firstly I would say: post some code, because there's not really enough information to diagnose anything for sure.

Secondly: it sounds as though you have a lot of threads for your property updating. If you have more threads than you have processors on your machine, you are most likely slowing your code down more than you're speeding it up.

Further, it sounds like you're doing a lot of work work every 1ms on a timer. That being the case, I would guess that you're thrashing your system too aggressively - unless you're sure that everything you mention in your question is running in < 1ms. Depending on how you're handling the timer, it's possible that you have multiple iterations of your code stacking up, which would also contribute to the loss in performance.

My advice would be:

  • drop everything down to just a couple of threads (one for property update handling, one for your timer) - it sounds as though you have far too many
  • reduce the frequency of your timer. In fact, get rid of the timer and test against a single iteration to see what your one-off update time is, and then bring the timer back in to understand how that's affecting performance (if at all)
  • profile, profile, profile to understand the problem
于 2013-09-04T12:59:34.993 回答