Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve perf for iterating over tracked entities
Part of #8898 Fixes #14231 Investigation into DbSet.Local shows that: * Iteration over tracked entities had a lot of LINQ code; fixed by un-LINQing * Multiple composed iterators cause slow-down; fixed by giving LocalView it's only IStateManager method * Filtering causes slow-down; fixed by splitting storage into multiple dictionaries. Makes lookup for entity instance slightly slower. * Calculate Count lazily This means that DbSet.Local iteration is now about 3x faster, although it depends a lot on what is being tracked. Getting an ObservableCollection and then iterating over that _once_ is slower than just iterating over the entries once. Iterating over the ObservableCollection multiple times is still faster than iterating over DbSet.Local multiple times. This seems like a reasonable trade-off. If the application does heavy iteration, then creating a new collection for that seems reasonable. With regard to #8898, the layering we have still seems correct, so moving forward with the breaking changes there.
- Loading branch information