Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async operation takes 130x longer to finish on a nvarchar(MAX) field comparing to a sync operation #22331

Closed
daniel3303 opened this issue Aug 31, 2020 · 3 comments

Comments

@daniel3303
Copy link

daniel3303 commented Aug 31, 2020

When a modal from the database where a column has a long string (I tested with a 9MB string) it takes around 130x more if you use an async operation.

Steps to reproduce

public class File {
        public int Id { get; set; }
        public string Base64{ get; set; }
}

public IActionResult Index() {
      var file = _dbContext.Files.Find(1); // The property Base64 has a 9MB random Base64 string
      return Ok(file.Base64); // Takes 0.2s
}

public async Task<IActionResult> Index() {
      var file = await _dbContext.Files.FindAsync(1);
      return Ok(file.Base64); // Takes 25.9s
}

Further technical details

EF Core version: v5.0.0-preview.8.20407.4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 5.0
Operating system: macOS Catalina and Windows 10 (happens in both)
IDE: Visual Studio 2019 16.7 and Rider 2020.01 (tested in both)

@smitpatel
Copy link
Member

@roji to find dupe.

@roji
Copy link
Member

roji commented Aug 31, 2020

Duplicate of dotnet/SqlClient#593

@roji roji closed this as completed Aug 31, 2020
@roji
Copy link
Member

roji commented Aug 31, 2020

See also dotnet/SqlClient#689 which is a dup of the above specifically for text data.

Unfortunately you'll have to use sync for now, or drop down to ADO.NET and use the streaming API, which does work efficiently in async.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants