Six seconds warmup time for the first entity framework 6 nonquery

entity-framework entity-framework-6

Question

According to my integration test:

// Act
Stopwatch w = new Stopwatch();
w.Start();
userService.Create(userDTO);
w.Stop();


public void Create(UserDTO userDTO)
{
    var user = userDTO.ToEntity();
    _context.Entry(user).State = EntityState.Added;
    _context.SaveChanges();
}

6,2 seconds is absurdly long for a "sql insert." I already hear users of the application grumbling when they initially launch a project that they use all year. They must therefore wait 6 seconds each day.

I believed that EF6's warm-up period had improved.

Is there anything I can do to change this dreadful attitude?

1
4
12/13/2013 11:42:21 AM

Accepted Answer

Give zzz-5 a try. By shifting work that would have to be done at runtime to design time, pre-generated views decrease the time it takes for an application to launch. more details

2
12/13/2013 6:19:09 PM

Popular Answer

Simple data entry does not take much time. The time you invested is where EF generates the model in memory.

When you perform an action on context for the first time, EF constructs an entity data model and runs view generation (instead of database views). Look at the numbers this article.

Check out here to see how using pre-generated views can increase performance and speed up model loading.

When your application launches, you can initialize your context async to optimize speed. Watch out for multithreading problems.

using (var context = new MyContext())
{
    context.Database.Initialize(false);
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow