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

(fix): Only execute certain operations once while handling results #3116

Conversation

epochcoder
Copy link
Contributor

@epochcoder epochcoder commented Mar 21, 2024

While creating benchmarks and profiling for the constructor injection ticket, I stumbled upon two cases which could be optimised, and both reduce memory allocation and runtime for very large result sets.

I did not want to include this in the previous PR as it is already huge, and these two improvements can be standalone.
Here are the benchmarking results using the same benchmark I created for the previously mentioned ticket.

Benchmark                                                                        Mode  Cnt  Score   Error  Units
PropertyVsConstructorInjectionBenchmark.retrieveAllUsingConstructorInjection     avgt    5  0.817 ± 0.036  ms/op
PropertyVsConstructorInjectionBenchmark.retrieveAllUsingPropertyInjection        avgt    5  1.067 ± 0.013  ms/op
PropertyVsConstructorInjectionBenchmark.retrieveSingleUsingConstructorInjection  avgt    5  0.046 ± 0.003  ms/op
PropertyVsConstructorInjectionBenchmark.retrieveSingleUsingPropertyInjection     avgt    5  0.037 ± 0.001  ms/op

For easy reference, here are the same benchmarks without this change:

Benchmark                                                                        Mode  Cnt  Score   Error  Units
PropertyVsConstructorInjectionBenchmark.retrieveAllUsingConstructorInjection     avgt    5  0.834 ± 0.015  ms/op
PropertyVsConstructorInjectionBenchmark.retrieveAllUsingPropertyInjection        avgt    5  1.164 ± 0.055  ms/op
PropertyVsConstructorInjectionBenchmark.retrieveSingleUsingConstructorInjection  avgt    5  0.045 ± 0.001  ms/op
PropertyVsConstructorInjectionBenchmark.retrieveSingleUsingPropertyInjection     avgt    5  0.038 ± 0.002  ms/op

As you can see, it does not really affect retrieving a single row, but improvements start to accumulate as our result set gets bigger

@coveralls
Copy link

Coverage Status

coverage: 87.118% (+0.001%) from 87.117%
when pulling 7e03261 on epochcoder:fix/minor-performance-improvement-resultsethandler
into 0ec8fcb on mybatis:master.

@epochcoder epochcoder closed this Mar 25, 2024
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.

2 participants