Skip to content

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

Closed
Wraith2 wants to merge 1 commit into
dotnet:mainfrom
Wraith2:rework-taskfactoryasync
Closed

Perf: Cache delegates for non query and xml reader calls#1194
Wraith2 wants to merge 1 commit into
dotnet:mainfrom
Wraith2:rework-taskfactoryasync

Conversation

@Wraith2

@Wraith2 Wraith2 commented Jul 28, 2021

Copy link
Copy Markdown
Contributor

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

Wraith2 commented Jul 31, 2021

Copy link
Copy Markdown
Contributor Author

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