Fix parallel tests execution, fix potential collisions, cache only regexes #2092
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Let me explain all these changes:
I replaced the static Dictionary with ConcurrentDictionary since its content could be updated by multiple threads. Looks like it is not happening in real scenarios, but the Dictionary breaks almost every time I run unit tests because of
[assembly: Parallelizable(ParallelScope.Fixtures)]
. The more CPU cores you have, the more chances to break the Dictionary.Previous approach to cache something by the GetHashCode() value is wrong because of possible collisions. The more commits you have - the more chances to face a collision (for example, "fix foo +semver:major" and "my commit +semver:patch" messages potentially could have the same hash code, and if it so, the result will depend on the order of this commits in history).
Looks like there is no reason to cache increments by commit message text. I believe that it's unusual to have a lot of commits with the same name in real world scenarios. Besides, when the repo has a lot of commits, there will be a huge memory footprint.
Bump messages are likely to stay default, so it's reasonable to turn default patterns to static compiled regexes, and also compile and cache custom regexes.
I also copy reference to intermediateCommitCache to the local variable before use it because of possible issues with multithreading.