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

ArC: speed up bean resolution at runtime #33760

Merged
merged 1 commit into from
Jun 5, 2023

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Jun 1, 2023

Specifically, the invocation of BeanManaget#getBeans() and the first hit for any programmatic lookup.

We use a precomputed map of a raw type to the set of matching beans which reduces the number of beans we need to iterate over when we're looking for matching beans.

Note that BeanManaget#getBeans() does not use the computing cache of results so this optimizaton results in a significant speed-up. On the other hand, the precomputed map could be memory demanding for large applications.

@quarkus-bot quarkus-bot bot added the area/arc Issue related to ARC (dependency injection) label Jun 1, 2023
@mkouba mkouba requested review from Ladicek and manovotn June 1, 2023 07:19
@mkouba
Copy link
Contributor Author

mkouba commented Jun 1, 2023

This PR is related to #33693.

@mkouba
Copy link
Contributor Author

mkouba commented Jun 1, 2023

Note that this is a runtime optimization. I didn't find a reasonable build-time alternative. Reasonable in terms of performance gain and complexity.

CC @franz1981 @Sanne

@mkouba mkouba marked this pull request as ready for review June 1, 2023 07:22
Copy link
Contributor

@Ladicek Ladicek left a comment

Choose a reason for hiding this comment

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

LGTM. Memory overhead should be pretty low, because all the objects (except of the maps and lists) must exist anyway [1], but some measurements would be good.

[1] I'm actually not sure about the String keys in the map. I'd personally use the Class object as the key, because that must exist. Looking at JDK 11's java.lang.Class, the getName() method initializes the class name lazily, so that String probably doesn't need to exist, but it's entirely possible we force it into existence elsewhere.

@mkouba mkouba force-pushed the arc-speedup-beanmanagergetbeans branch from bd1f32b to 22320ef Compare June 1, 2023 09:37
Copy link
Contributor

@manovotn manovotn left a comment

Choose a reason for hiding this comment

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

I like this solution, it's IMO a good middle ground between what we had and going bonkers on over optimizing this code :)

@mkouba
Copy link
Contributor Author

mkouba commented Jun 1, 2023

I'm actually not sure about the String keys in the map. I'd personally use the Class object as the key, because that must exist. Looking at JDK 11's java.lang.Class, the getName() method initializes the class name lazily, so that String probably doesn't need to exist, but it's entirely possible we force it into existence elsewhere.

@Ladicek Let's keep it this way for now. We could change it later, once we measure the RSS and find out that there's too much overhead... WDYT?

@mkouba mkouba added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jun 1, 2023
@Ladicek
Copy link
Contributor

Ladicek commented Jun 1, 2023

I already approved, so I'm fine :-)

@mkouba mkouba force-pushed the arc-speedup-beanmanagergetbeans branch from 22320ef to 1ecd5bf Compare June 1, 2023 13:38
@Sanne
Copy link
Member

Sanne commented Jun 1, 2023

Very nice, thanks for looking at this so quickly!

@quarkus-bot

This comment has been minimized.

Specifically, the invocation of BeanManaget#getBeans() and the first hit
for any programmatic lookup.

We use a precomputed map of a raw type to the set of matching beans
which reduces the number of beans we need to iterate over when we're
looking for matching beans.

Note that BeanManaget#getBeans() does not use the computing cache of
results so this optimizaton results in a significant speed-up. On the
other hand, the precomputed map could be memory demanding for large
applications.
@mkouba mkouba force-pushed the arc-speedup-beanmanagergetbeans branch from 1ecd5bf to d582a45 Compare June 2, 2023 06:46
@quarkus-bot

This comment has been minimized.

@quarkus-bot
Copy link

quarkus-bot bot commented Jun 2, 2023

Failing Jobs - Building d582a45

Status Name Step Failures Logs Raw logs
Native Tests - Amazon Build Failures Logs Raw logs

Full information is available in the Build summary check run.

Failures

⚙️ Native Tests - Amazon #

- Failing: integration-tests/amazon-lambda integration-tests/amazon-lambda-http 

📦 integration-tests/amazon-lambda

io.quarkus.it.amazon.lambda.AmazonLambdaSimpleIT.testSimpleLambdaSuccess - More details - Source on GitHub

java.lang.RuntimeException: 
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.amazon.lambda.deployment.DevServicesLambdaProcessor#startEventServer threw an exception: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.net.BindException: Address already in use

📦 integration-tests/amazon-lambda-http

io.quarkus.it.amazon.lambda.AmazonLambdaSimpleIT.testJaxrsCognitoJWTSecurityContext - More details - Source on GitHub

java.lang.RuntimeException: 
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.amazon.lambda.deployment.DevServicesLambdaProcessor#startEventServer threw an exception: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.net.BindException: Address already in use

@mkouba
Copy link
Contributor Author

mkouba commented Jun 5, 2023

The failures in the integration-tests/amazon-lambda-http are unrelated, i.e. it fails in other PRs as well.

@mkouba mkouba merged commit ca0ad11 into quarkusio:main Jun 5, 2023
@quarkus-bot quarkus-bot bot removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jun 5, 2023
@quarkus-bot quarkus-bot bot added this to the 3.2 - main milestone Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants