NEventStore/NEventStore — pull request #281 by danielmarbach (2013-10-18 13:00:58+00:00)
Title: DuplicationDetection and ConcurrencyConflictCheck uses dedicated HashSet to improve InMemory Performance

This pull trades memory consumption in favor of performance. My personal point of view is that it is more important to have good performance than saving a lot of memory in the in memory persistance. In the end the performance also matters here because this greatly improves the execution time of the tests relying on the in memory persistance. I ran some analysis on the current master and detected that a 94% of the time is spend in the duplication detection. This uses an Any() clause which gets extremely inefficient the more items you have in the persistance. This pull add an aproximate overhead of 2% memory consumption but improves the performance in order of magnitudes:

Number of events	Before (ms)	PerfBefore	MemoryBefore	After (ms)
10000	5484	94% DetectDuplicates	65 KB	656
10000	5492	No longer bottleneck	67 KB	486
15000	12651	857
15000	12389	655
20000	22585	967
20000	22333	815
40000	115865	1728
100000	XXXXXX	3942
1000000	35987

So with 40000 events the performance is now 67 times better than before!

Here are the perf and memory snapshots from my machine:

https://dl.dropboxusercontent.com/u/9580212/NEventStorePerformance.zip

My machine has the following specs

![2013-10-18 14_59_56-system](https://f.cloud.github.com/assets/174258/1360409/4199ffcc-37f5-11e3-8803-64af777b1ea9.png)

I have a SSD drive in my notebook.