Skip to content

Cache generic param names #3176

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

Merged
merged 2 commits into from
Jun 12, 2024
Merged

Cache generic param names #3176

merged 2 commits into from
Jun 12, 2024

Conversation

kang-hl
Copy link
Contributor

@kang-hl kang-hl commented Jun 7, 2024

No description provided.

@coveralls
Copy link

Coverage Status

coverage: 87.175% (+0.005%) from 87.17%
when pulling a854fa8 on kang-hl:add-cache
into e836410 on mybatis:master.

@hazendaz
Copy link
Member

hazendaz commented Jun 9, 2024

@harawata Any concerns here? I don't see any real difference on processing of a build along with tests from any outstanding builds. This is probably very micro here at caching so not fully seeing the value. Plus seems odd that we prep for full 255 when that number is probably more often than not too high.

@harawata
Copy link
Member

Yeah. It is rare to see a statement with 5+ parameters.

It might be possible to cache only the first five or ten names and create the others on the fly, but it requires an extra check, so ... I'm not sure.

genericParamName = i < 10 ? CACHED[i] : PREFIX + (i + 1);

@kang-hl
Copy link
Contributor Author

kang-hl commented Jun 10, 2024

Yeah. It is rare to see a statement with 5+ parameters.

It might be possible to cache only the first five or ten names and create the others on the fly, but it requires an extra check, so ... I'm not sure.

genericParamName = i < 10 ? CACHED[i] : PREFIX + (i + 1);

Adding an environment variable to change this value may be better.

1 similar comment
@kang-hl
Copy link
Contributor Author

kang-hl commented Jun 10, 2024

Yeah. It is rare to see a statement with 5+ parameters.

It might be possible to cache only the first five or ten names and create the others on the fly, but it requires an extra check, so ... I'm not sure.

genericParamName = i < 10 ? CACHED[i] : PREFIX + (i + 1);

Adding an environment variable to change this value may be better.

@harawata
Copy link
Member

@kang-hl ,

I prefer not to add a new config option for this.
How many parameters does your statement actually have?

@kang-hl
Copy link
Contributor Author

kang-hl commented Jun 10, 2024

@kang-hl ,

I prefer not to add a new config option for this. How many parameters does your statement actually have?

Only a few at most, but not everyone is like this. Can only add one environment variable or an extra check or keep it as is, which one do you prefer?

@harawata
Copy link
Member

Let's just cache the first ten names.
It covers more than 95%, I believe.

And we can change it anytime if we need to.

@kang-hl
Copy link
Contributor Author

kang-hl commented Jun 12, 2024

Let's just cache the first ten names. It covers more than 95%, I believe.

And we can change it anytime if we need to.

Modified.

@@ -132,7 +140,7 @@ public Object getNamedParams(Object[] args) {
for (Map.Entry<Integer, String> entry : names.entrySet()) {
param.put(entry.getValue(), args[entry.getKey()]);
// add generic param names (param1, param2, ...)
final String genericParamName = GENERIC_NAME_PREFIX + (i + 1);
final String genericParamName = GENERIC_NAME_CACHE[i];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for i > 10 this will return a ArrayIndexOutOfBoundsException,

@coveralls
Copy link

Coverage Status

coverage: 87.175% (+0.005%) from 87.17%
when pulling 859a254 on kang-hl:add-cache
into e836410 on mybatis:master.

@harawata harawata changed the title add a cache for genericParamName Cache generic param names Jun 12, 2024
@harawata harawata merged commit 9edc79a into mybatis:master Jun 12, 2024
19 checks passed
@harawata harawata added this to the 3.5.17 milestone Jun 13, 2024
@harawata harawata self-assigned this Jun 13, 2024
@harawata harawata added the polishing Improve a implementation code or doc without change in current behavior/content label Jun 13, 2024
@harawata
Copy link
Member

Thank you for the PR, @kang-hl !
And thank you for the review, @epochcoder !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
polishing Improve a implementation code or doc without change in current behavior/content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants