Paymentsense / Dapper.SimpleLoad

Dapper.SimpleLoad
MIT License
13 stars 4 forks source link

Add caching of AutoQueries to improve performance #6

Open bartread opened 8 years ago

bartread commented 8 years ago

Generating auto-queries can be expensive since reflection is used to walk over the types and generate SQL. The SQL itself can become quite large so there's a lot of appending to StringBuilders happening, which will obviously cause allocations and copying.

It would be better to cache auto-queries based on criteria such as:

You don't need to cache anything for calls to CustomQuery because Dapper will cache the queries itself. With AutoQueries this is just a way of avoiding large amounts of SQL generation for frequently repeated queries, which should noticeably improve performance under load.

bartread commented 8 years ago

I think caching the TypePropertyMaps as well might be a good shout, based on what ANTS Performance Profiler is showing me.

It also seems as though the most expensive part of the query generation is creating the SELECT list.