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

Perf: Cache delegates for non query and xml reader calls #1194

Closed
wants to merge 1 commit into from

Conversation

Wraith2
Copy link
Contributor

@Wraith2 Wraith2 commented Jul 28, 2021

When using ExecuteNonQueryAsync and ExecuteXmlReaderAsync begin and end delegates are passed to Task<T>.Factory.FromApm and because these are instance methods they cannot be cached meaning we have two delegates allocated per call. ExecuteNonQueryAsync is a very commonly used method so even small improvements here can have a large impact overall.

I followed the general pattern introduced and used in ExecuteReaderAsync. I created static versions of the begin and end functions needed for each of the FromApm calls and made sure that the instance was passed as a state variable, the static functions simply unpack the instance from state and call the correct method on the instance. The static delegates are then cached as static readonly and re-used every time a call is made.

Note that the netfx version of ExecuteReaderAsync has not been altered because it will be dealt with by #1084

@Wraith2
Copy link
Contributor Author

Wraith2 commented Jul 31, 2021

I'm closing this because there is a cleaner and lower impact way to do this once #1084 has been merged.

@Wraith2 Wraith2 closed this Jul 31, 2021
@Wraith2 Wraith2 deleted the rework-taskfactoryasync branch October 6, 2021 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant