Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

QueryAsync<T> 性能

Open 759085503 opened this issue 3 years ago • 7 comments

版本2.0.123 使用全表查询耗时7S多。数据条数2W条,列数52列。 反射的时候耗时。数据库查询0.5S。不知道如何优化,请帮忙给出意见,谢谢

759085503 avatar Mar 22 '22 02:03 759085503

数据库类型mysql

759085503 avatar Mar 22 '22 02:03 759085503

Version 2.0.123 It takes more than 7S to use the full table query. The number of data bars is 2W, and the number of columns is 52. Time consuming when reflecting. Database query 0.5S. I don't know how to optimize it, please help me, thank you

(Via Google Translate)

mgravell avatar Mar 22 '22 07:03 mgravell

When you say "database query 0.5S" - what are you comparing there? Is that the time to execute the same query via ADO.NET and iterate the same.results manually? Usually, this kind of problem is either data volume (bandwidth) related, or the RDBMS performance. Dapper can't fix either of those things, so knowing what we're comparing is essential.

mgravell avatar Mar 22 '22 07:03 mgravell

image Ok, so let's say again, what I'm using here is a schematic of Dapper versus EF Code

759085503 avatar Mar 22 '22 07:03 759085503

I have debugged your source code, it is slow to reflect entities, as long as there are many columns will have this slow problem, if I return fewer columns is very good

759085503 avatar Mar 22 '22 08:03 759085503

image

759085503 avatar Mar 22 '22 08:03 759085503

It isn't really using reflection here, per row; it use ref-emit to generate optimized IL that is then reused aggressively. If having lots of columns is impacting you, then this is more likely to be a row-width bandwidth problem, usually related to large string or binary data in the many columns. Note also that this doesn't always show in ad-hoc query tools (like SSMS or the equivalent for your RDBMS), because those ad-hoc tools usually specify a relatively short text/binary width, and display "your text ...(truncated)" or similar if it overflows.

mgravell avatar Mar 23 '22 07:03 mgravell