Description
Hello,
var ctx = new DbContextSG(options);
ctx.ChangeTracker.AutoDetectChangesEnabled = false;
// should this disabled the creation of LazyLoader() ?
ctx.ChangeTracker.LazyLoadingEnabled = false;
public class Customer {
public DbContext DbContext { get; set; } // has only minor performance impact
public ILazyLoader LazyLoader { get; set; } // has Huge performance impact
}
for (int i = 0; i < 100_000; i++)
{
var c1 = new Customer();
ctx.Customers.Add(c1); // attaches entitiy to the context in state "Added", also creates and injects all Services
// side note: `ctx.AddRangeAsync()` does not do a batch action, it's slow and Synchronous, the name Async is confusing.
}
A few things i've noticed: Injecting the ILazyLoader is slow.
Around 30% slower than not having the "ILazyLoader LazyLoader" property in my customer object.
The 100k loop takes: 1300ms vs 1000ms without "ILazyLoader LazyLoader".
The LazyLoader is created and injected for new Entities.
The LazyLoader is created and injected for all Entities of all Queries.
The LazyLoader is created and injected if "ChangeTracker.LazyLoadingEnabled = false"
Is this the desired behaviour?
I feel like we can save some resources here if we don't create and inject 100k of LazyLoader() that are not needed.
Are LazyLoader objects ever needed for new entities?
I would love to disable the creation of LazyLoader objects if i know that i don't need LazyLoaders for a query.
Best Regards