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

Save regexp Pattern allocation on config name renaming #39444

Merged
merged 2 commits into from
Mar 14, 2024

Conversation

franz1981
Copy link
Contributor

@franz1981 franz1981 commented Mar 14, 2024

This is addressing a small regression in case some old names are used, saving allocating (for each replacement) a whole new regexp Pattern and creating a reusable function which does it "right" if compared to String:.replaceFirst.

I've than removed the method reference lambda generation to match what we do elsewhere, but I have not a strong opinion here, considered that it mostly affect RSS footprint while the application doesn't do anything interesting (sadly a case still valuable in public benchmarks :/ ) - see #36204 (comment) for more info at java/lang/invoke/LambdaForm.compileToBytecode.
In JDK 21 it's likely lambdas RSS footprint is reduced and who knows for later releases, so, as said, I've performed the change here, but I could have made the interceptors to implements Function<String, String and just pass this to their super constructor too, not getting lambdas nor anonymous class loaded, at all.

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

I agree with your change but the order of arguments is not always the same and I think you copy/pasted things a bit too much.

I will adjust and force push.

if (!name.startsWith(oldPrefix)) {
return name;
}
// don't use here String::replaceFirst because it uses regex
Copy link
Member

Choose a reason for hiding this comment

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

Ah f**k. I thought replaceFirst was like replace and not using regexp :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was surprised as well! Said that, you know that this change I'm pushing is a drop in the ocean which value is mostly on benchs as far as I can tell :/
And likely, the renaming will goes away in few releases too

@gsmet gsmet force-pushed the no_pattern_allocation branch from fa48b97 to 73ff652 Compare March 14, 2024 17:36
Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

I amended your commit to make sure the method was always called with the parameters in the correct order (relocate and fallback are symmetrical).

I also added a small test for your util as better to have it tested.


@Test
public void testChangePrefix() {
assertEquals("quarkus.new-prefix.configuration-property", StringUtil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice one!

private static final Function<String, String> RENAME_FUNCTION = new Function<String, String>() {
@Override
public String apply(String s) {
return StringUtil.changePrefix(s, NEW_PREFIX, OLD_PREFIX);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gsmet My ide has been smarter than me and I fix it back (making it wrong) later on, uff :/ many thanks to have found it!

@franz1981
Copy link
Contributor Author

Thanks @gsmet for the review 🙏

Copy link

quarkus-bot bot commented Mar 14, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 73ff652.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

@gsmet gsmet merged commit 9560cc8 into quarkusio:main Mar 14, 2024
49 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.10 - main milestone Mar 14, 2024
@gsmet
Copy link
Member

gsmet commented Mar 14, 2024

Thanks, good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants