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

Mitigate performance regressions #1772

Closed
wants to merge 5 commits into from
Closed

Mitigate performance regressions #1772

wants to merge 5 commits into from

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Apr 16, 2024

See #1721

mp911de added 3 commits April 15, 2024 09:15
We now create RowMapper/ResultSetExtractor instances only once if they are considered static configuration.

A configured RowMapper ref/class is always static. A configured ResultSetExtractor ref/class is static when the extractor does not accept a RowMapper or if the RowMapper is configured.

Default mappers or projection-specific ones require ResultSetExtractor recreation of the ResultSetExtractor is configured as Class.

Also, reuse TypeInformation for RelationalParameter instead of recreating it.
Reuse TypeInformation as much as possible to avoid Class -> TypeInformation conversion.
Introduce LRU cache for DefaultAggregatePath to avoid PersistentPropertyPath lookups.
Introduce best-effort quoted cache for SqlIdentifier to avoid excessive string object creation.
@mp911de mp911de added the type: regression A regression from a previous release label Apr 16, 2024
@mp911de mp911de requested a review from schauder April 16, 2024 13:54
Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

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

Looks good to me. With one more potential improvement outlined.

@@ -192,7 +192,7 @@ private JdbcQueryExecution<?> getJdbcQueryExecution(@Nullable ResultSetExtractor
if (getQueryMethod().isModifyingQuery()) {
return createModifyingQueryExecutor();
} else {
return createReadingQueryExecution(extractor, rowMapper);
return createReadingQueryExecution(extractor, () -> rowMapper);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we replace the parameter rowMapper with a Supplier? This method is called a single time and the rowMapper is constructed right before that usage so converting it to a Supplier should be fairly simple.

Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

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

The changes in DerivedSqlIdentifier and DefaultSqlIdentifier look weird to me.
Once that is resolved I'm fine with merging it.

this.sql = processing;
return sqlName;
String normalized = processing.standardizeLetterCase(name);
this.sqlName = sqlName = new CachedSqlName(processing, quoted ? processing.quote(normalized) : normalized);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks really weird to my old Java eyes.
And I don't even understand why you have the local variable sqlName in the first place.
If it isn't a left over from editing, we should explain it with a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

The light-weight cache is volatile. Any comparison to the field are only valid for the duration of a single instruction. Therefore, we copy the cached field value into a local variable and do our comparisons there. After we discover that we should create a new cached variant, we create CachedSqlName, assign it into the local variable and the volatile field in a single line.

@@ -57,7 +58,7 @@ public abstract class Jsr310TimestampBasedConverters {
*/
public static Collection<Converter<?, ?>> getConvertersToRegister() {

List<Converter<?, ?>> converters = new ArrayList<>(8);
List<Converter<?, ?>> converters = new ArrayList<>(28);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 28?

Copy link
Member Author

Choose a reason for hiding this comment

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

Meh, that was a leftover from the code below (TODO). We should discuss that one.

@schauder
Copy link
Contributor

Merged.

@schauder schauder closed this Apr 23, 2024
@schauder schauder added this to the 3.2.6 (2023.1.6) milestone Apr 23, 2024
@sdeleuze
Copy link
Contributor

Thanks for working on this, much appreciated.

@schauder schauder deleted the issue/1721 branch June 7, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants