Any idea why this code takes 49 ms
public void OnGet(String sessionId)
{
BackgroundEntry = _context.BackgroundEntry.Where(x => x.Id == sessionId).ToList();
}
but this code takes 300+ ms?
public async Task OnGetAsync(String sessionId)
{
BackgroundEntry = await _context.BackgroundEntry.Where(x => x.Id == sessionId).ToListAsync();
}
I would expect the same time for both. Tested this in various conditions and it always the same, async has 300+ ms delay.
BackgroundEntry is autogen by EF:
public partial class BackgroundEntry
{
public string Id { get; set; }
public string Part { get; set; }
public long Datetime { get; set; }
public DateTime CreatedAt { get; set; }
public Guid Session { get; set; }
public string Action { get; set; }
public string Domain { get; set; }
public string Location { get; set; }
public long? LastEntryDatetime { get; set; }
public BackgroundEntry BackgroundEntryNavigation { get; set; }
public BackgroundEntry InverseBackgroundEntryNavigation { get; set; }
}
benchmark with stopwatch:
using (Models.RecorderContext context = new Models.RecorderContext())
{
sw.Start();
var BackgroundEntry = context.BackgroundEntry.Where(x => x.Id == sessionId).ToList();
sw.Stop();
}
var g = sw.ElapsedMilliseconds;
sw.Reset();
// g = 22 ms
using (Models.RecorderContext context = new Models.RecorderContext())
{
sw.Start();
var BackgroundEntry = await context.BackgroundEntry.Where(x => x.Id == sessionId).ToListAsync();
sw.Stop();
}
g = sw.ElapsedMilliseconds;
// g = 328 ms