FindAsync is slow but slow loading

In my code, I used loading the linked object using await FindAsync , hoping that I better comply with the async C # instructions.

 var activeTemplate = await exec.DbContext .FormTemplates.FindAsync(exec.Form.ActiveTemplateId); 

and it worked slowly, was slow in the sql server profiler, the query text was fast in SSMS. It took 5 seconds to get this line.

Alternative:

 var activeTemplate = exec.Form.ActiveTemplate; 

much faster. By all means, the problem, apparently, is not a parameterization, since the number of reads in fast and slow queries is the same.

One possible irrelevant point is that the extracted object contains a row property containing ~ 1 MB of text. An asp.net mvc application running on the same machine as the sql server using (local).

What is the reason for the observed slowness?

EDIT: after @ jbl's comment, I did a few more experiments:

 var activeTemplate = await exec.DbContext.FormTemplates .FirstOrDefaultAsync(x => x.Id == exec.Form.ActiveTemplateId); // slow var activeTemplate = exec.DbContext.FormTemplates .FirstOrDefault(x => x.Id == exec.Form.ActiveTemplateId); // fast 
+5
source share
1 answer

An asynchronous method may have performance issues when reading a large column from a server (e.g. varbinary (MAX), varchar (MAX), nvarchar (MAX), or XML).

You can find the rducom answer that explains the problem using the async method here

+5
source

Source: https://habr.com/ru/post/1242617/


All Articles