I had an application that was performing very poorly under a fairly heavy load out in the real world. It got me thinking about doing more performance testing, both within a profiler and under simulated loads. The profiler pointed out some key flaws in the code that were quickly dispatched, but the problems still remained.

I enlisted some help to simulate more realistic loads and really stressed out the application and I started getting errors that I shouldn’t have been getting. So I thought. The code that was generating the errors wasn’t thread-safe. In an effort to reduce the number of error emails I was receiving, I surrounded the offending code with SyncLocks and the errors stopped.

A side benefit was that the performance issues went away. It was then that I discovered that exceptions can cause some performance hits due to the extra objects required.

So, if you can help it, minimize exceptions (I could in this case) and watch for thread-safety in code that may be run with multiple threads.