YurePereira / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Patch for /Dapper/SqlMapper.cs Memory leak fix #66

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Prevent memory leaks that can occur (and did occur in my case while doing bulk 
inserts with no parameters) due to the caching of sql queries with no 
parameters as identities. This should also speed-up queries with no parameters.

Original issue reported on code.google.com by trader...@gmail.com on 26 Sep 2011 at 12:25

Attachments:

GoogleCodeExporter commented 8 years ago
I see what you mean, in terms of impact etc - but as a small note: if you are 
*doing* such an insert, it should *probably* be parameterised? Indeed, dapper 
allows you to pass an IEnumerable[*] to Execute, and it will automatically loop 
for you (allowing you to apply a template insert to a list of objects, for 
example).

Patch applied, but I wonder if you are doing something the hard way.

Original comment by marc.gravell on 26 Sep 2011 at 5:21

GoogleCodeExporter commented 8 years ago
I tried it this way, but given the very high number of inserts (in the 100k), 
it was not as efficient as hardcoding the query (with MySQL, using the syntax 
VALUES(...,...,...),(...,...,...).
Now if it is ever possible to parameterize this and let dapper do the 
conversion, that would be better indeed. Right now, using an array of parameter 
values, Dapper will submit a lot of single INSERT queries, which is fine for 
small queries but not suitable for bulk inserts.

If changing the current implementation is not recommended, it could be relevant 
to add an InsertBulk() query method, using the same parameter names for each 
row, and arrays of possible values, provided this can be supported by the 
ADO.NET layer.

Original comment by trader...@gmail.com on 26 Sep 2011 at 9:55

GoogleCodeExporter commented 8 years ago
I guess it could be done, perhaps in "Contrib" - i.e. write a wrapper that 
combines commands for minimum round-trips; the only problem is that it would 
need to know the maximum command size and (more pressingly) parameter count for 
that provider. Something to look at in the future, perhaps.

Original comment by marc.gravell on 26 Sep 2011 at 11:44

GoogleCodeExporter commented 8 years ago
In addition to the existing parameterization and inline value injection, I have 
now added a CommandFlags.NoCache option which achieves this

Original comment by marc.gravell on 5 Aug 2014 at 2:20