Skip to content
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

Consider cancelling the command in SaveChanges when an error occurs #30182

Open
roji opened this issue Jan 31, 2023 · 2 comments
Open

Consider cancelling the command in SaveChanges when an error occurs #30182

roji opened this issue Jan 31, 2023 · 2 comments

Comments

@roji
Copy link
Member

roji commented Jan 31, 2023

We currently limit the SaveChanges batch size (42 in SQL Server), among other things because if an error occurs (e.g. unique constraint), we don't want to continue sending a huge amount of useless data that will get rolled back anyway. The PG provider, by the way, has no such upper limit (see npgsql/efcore.pg#2630 for a recent complaint about this). Limiting the max batch size sacrifices performance for the good case (more roundtrips when no errors occur), so that the bad case is faster.

An alternative approach may be to simply attempt cancellation of the query when we see an error. FWIW this is what Dapper does, IIRC.

@stevendarby
Copy link
Contributor

Limiting the max batch size sacrifices performance for the good case (more roundtrips when no errors occur), so that the bad case is faster.

I think 42 was picked as the default because it was around the most optimal batch size found during an investigation (and, you know, the other reason...)

@roji
Copy link
Member Author

roji commented Jan 31, 2023

Yeah, that's a SQL Server-specific thing (the question above is general and concerns PostgreSQL as well). Importantly, there's a very good chance that if/when we manage to switch to the new batching API (#18990), the performance characteristics would change significantly and 42 would no longer be right.

@ajcvickers ajcvickers added this to the Backlog milestone Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants