Do not use ImmutableList for Events collections #113
Merged
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.
I noticed in my lab, which is a VM with limited CPUs, that if I open a large event log (~500,000 events) which is also very busy adding new events, choosing Load New Events from the view menu can make the app hang for several seconds. After doing some testing, I believe this is due to the use of ImmutableList.
Our Fluxor Store needs to produce immutable state, so ImmutableList seems like a natural choice for our event collections. We can't use IEnumerable, because we need to be able to index into the collection, and anyway, IEnumerable leaves it possible to modify the underlying collection.
ImmutableList would be fine for 100 or 1000 items, but when we have 500,000 events and we now need to concatenate two ImmutableLists to produce a new one for the state, it gets very expensive and very slow.
I compared Concat() performance between List<>, ImmutableList<>, and ReadOnlyCollection<>. This is starting with a collection of 50,000 items and then calling Concat 10,000 times to add 10,000 new items:
This is too high of a performance price to pay in a critical UI path, even if it might save us from accidentally modifying the underlying collection. We can use ReadOnlyCollection, which at least limits mutability somewhat, and as long as we are disciplined about making sure the Reducers always produce a new collection and don't mutate the old one, we should be fine.
Therefore, this PR drops ImmutableList for ReadOnlyCollection in the EventLogState.