-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Slowness when using large number of dynamic parameters #1537
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
Comments
I am having the same issue using SQL Server. I narrowed this down to the following line in DynamicParameters:
This is called for every single parameter, and the implementation (Microsoft.Data.SqlClient.SqlParameterCollection) is a loop of all parameters:
This combination makes this a n-squared algorithm which explains the slowness. As a workaround, you can use a custom implementation of
|
PR created #2037 |
When using a large number of query parameters, Dapper appears to take an extremely long time to add the parameters to the command before executing it. It took ~40 seconds to add 11k parameters.
I verified it was not an issue with casting or the query itself by grabbing the plan explanation for the query out of the logs. (I am using Postgres and used the auto explain module to generate it, which hopefully removes .) Running the query directly on the database executes fairly quickly (< 1 second)
I also used the debugger to verify it was an issue with Dapper itself - it looks like the majority of time is spent in the AddParameters method in the DynamicParameters class.
I also tested out explicitly specifying the db type of the parameter (DbString), as well as the length and input direction, but that did not seem to have any significant effect on the performance.
I do have a workaround, as this particular query can be split up into batches, I but just wanted to verify that this a limitation of Dapper, and make sure there isn't a different way to approach the problem.
Edit: Forgot to mention, I'm seeing this behavior with version 2.0.35.
The text was updated successfully, but these errors were encountered: