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

Produce quarkus.uuid lazily #45434

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Jan 8, 2025

This is done because bootstrapping the plumbing
needed by the JDK to produce a UUID value
is expensive, it thus doesn't make sense to
pay this cost when the property isn't actually
needed

The goal is the same as that of #33941

@geoand geoand mentioned this pull request Jan 8, 2025
@geoand geoand changed the title Make production of quarkus.uuid lazy Produce quarkus.uuid lazily Jan 8, 2025
@franz1981
Copy link
Contributor

Nice one!

@geoand
Copy link
Contributor Author

geoand commented Jan 8, 2025

🙏🏽 ❤️

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.

That would be awesome if it worked. It's a shame everybody pays the price for it.

Now I suppose anyone ending using the random infra will pay the price at some point but simple apps might not have any random around so it would clearly be a win.

Comment on lines -77 to -84
/**
* A property that allows accessing a generated UUID.
* It generates that UUID at startup time. So it changes between two starts including in dev mode.
* <br>
* Access this generated UUID using expressions: `${quarkus.uuid}`.
*/
Optional<String> uuid();

Copy link
Member

Choose a reason for hiding this comment

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

Does it actually change something to remove this? Asking because it's the only way to document it in the config.

Copy link
Member

Choose a reason for hiding this comment

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

If a property is declared in a mapping (or the old root), it is always eagerly populated. It wouldn't matter if quarkus.uuid is lazy. This is always trigger the load.

Copy link
Member

Choose a reason for hiding this comment

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

OK. I suppose we need to make sure it's properly documented elsewhere then.

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to do it manually. We don't have a way to do it in the processor. We can ignore properties for documentation, but we can't ignore properties for mapping.

@@ -12,7 +15,38 @@ public class RuntimeConfigBuilder implements SmallRyeConfigBuilderCustomizer {
@Override
public void configBuilder(final SmallRyeConfigBuilder builder) {
new QuarkusConfigBuilderCustomizer().configBuilder(builder);
builder.withDefaultValue("quarkus.uuid", UUID.randomUUID().toString());
builder.withSources(new ConfigSource() {
Copy link
Member

Choose a reason for hiding this comment

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

Looks interesting. If the ConfigSource are kept around at runtime, we might want to move this to a static nested class to avoid keeping the builder reference around?

That being said, better to wait for @radcortez 's feedback before polishing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 on all counts

Copy link
Member

Choose a reason for hiding this comment

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

If we want a quick solution, I'm okay with moving forward with this.

My idea was to add some sort of lazy type that can be declared in the mapping. This would allow keeping the declaration for documentation purposes and flattening sources if there are other cases.

Alternatively, we could just do this as a build step for the extensions that need it (it would have worked if it was done that way when it was first introduced). Unfortunately, we can't tell if users are now relying on it outside of the required extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we want a quick solution, I'm okay with moving forward with this.

That's totally up to you. The reason I vote for having this now is that we usually do the performance optimization in sprints (I don't mean the Agile sense of the word) and if we don't get this in now, who knows when we'll get around to it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In any case, I updated the PR to use an inner class instead of an anonymous one.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's worth merging this but I also agree having a lazy type in SmallRye Config would be nice for the future and we could revisit this patch then.

Copy link
Member

Choose a reason for hiding this comment

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

BTW, another alternative (breaking) is to totally drop this from the Config system and add a specific API for it (this is similar to the issue we have with ports).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought of that, but this property seems pretty pervasive so I didn't want to cause such problems until after the next LTS :)

This is done because bootstrapping the plumbing
needed by the JDK to produce a UUID value
is expensive, it thus doesn't make sense to
pay this cost when the property isn't actually
needed
@geoand geoand marked this pull request as ready for review January 8, 2025 13:21
@geoand geoand added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jan 8, 2025

This comment has been minimized.

@gsmet
Copy link
Member

gsmet commented Jan 8, 2025

FWIW, the fault tolerance issue is unrelated, it popped up in other PRs. I pinged @Ladicek with the details in another PR.

@geoand
Copy link
Contributor Author

geoand commented Jan 8, 2025

🙏

@radcortez
Copy link
Member

FWIW, the fault tolerance issue is unrelated, it popped up in other PRs. I pinged @Ladicek with the details in another PR.

Ah, good to hear, I was going crazy thinking I caused it in another PR :)

@gsmet
Copy link
Member

gsmet commented Jan 9, 2025

We need to be careful though as it gets the build stuck so PRs are not properly tested: anything beyong these tests is not exercised...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config area/core triage/waiting-for-ci Ready to merge when CI successfully finishes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants