-
Couldn't load subscription status.
- Fork 3.3k
Description
In long term contexts the DetectChanges-Method is slow when a lot of objects are tracked. It's a linear or polynomial complexity problem.
See: https://github.com/dotnet/efcore/blob/release/8.0/src/EFCore/ChangeTracking/Internal/ChangeDetector.cs#L129
foreach (var entry in stateManager.ToList()) // Might be too big, but usually _all_ entities are using Snapshot tracking
This could be avoided by a redesign of the change tracker. My suggestions would be, that during the reflection phase where the entity classes are analyzed also some known interfaces should be recognized. In this context it would be the INotifyPropertyChanged-Interface. If a entity class implements this interface and the change tracker is configured as let's call it "Just-In-Time-Tracking-Mode", then changed entites has to be registered in different fast collections according it's EntityState. And a further method should be provided similiar to the historic System.Data.Objects.ObjectStateManager.GetObjectStateEntries() where the searched EntityStates can be passed.
I'm aware that's a critical and central core feature. Especially because of the risk of memory leaks if the garbage collector cannot free objects if events have not been properly unsubscribed. But I would be very happy if such important core-features from previous EF-Versions would be prioritized highly.