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 - add "remove unused beans" optimization #552

Merged
merged 2 commits into from
Jan 18, 2019

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Jan 17, 2019

So this is basically a framework-level dead code elimination. The container attempts to remove all unused beans before the wiring metadata classes are generated. The algorithm is described in javadoc and is very similar to the Weld implementation.

The optimization is enabled by default, but could be disabled by shamrock.arc.remove-unused-beans=false.

Extensions can register BeanRemovalExclusionBuildItems to eliminate false positives such as JAX-RS resources (in general application entry points and beans that are only accessed programatically).

In terms of build times - for quickstarts/getting-started the difference is:

[DEBUG] [org.jboss.protean.arc.processor.BeanDeployment] Bean deployment created in 53 ms
[DEBUG] [org.jboss.protean.arc.processor.BeanDeployment] Removed 11 unused beans in 5 ms
[DEBUG] [org.jboss.protean.arc.processor.BeanDeployment] Bean deployment initialized in 14 ms
[DEBUG] [org.jboss.protean.arc.processor.BeanProcessor] Generated 9 resources in 27 ms
[DEBUG] [org.jboss.builder] Finished step "org.jboss.shamrock.arc.deployment.ArcAnnotationProcessor.build" in 174 ms

[DEBUG] [org.jboss.protean.arc.processor.BeanDeployment] Bean deployment created in 52 ms
[DEBUG] [org.jboss.protean.arc.processor.BeanDeployment] Bean deployment initialized in 8 ms
[DEBUG] [org.jboss.protean.arc.processor.BeanProcessor] Generated 31 resources in 57 ms
[DEBUG] [org.jboss.builder] Finished step "org.jboss.shamrock.arc.deployment.ArcAnnotationProcessor.build" in 193 ms

So the build is a bit faster and we generate 22 classes less.

@mkouba mkouba requested a review from manovotn January 17, 2019 12:41
@mkouba mkouba added this to the 0.7.0 milestone Jan 17, 2019
@mkouba mkouba requested a review from stuartwdouglas January 17, 2019 13:42
@@ -70,4 +72,9 @@ BeanContainerListenerBuildItem build(

}

@BuildStep
public BeanRemovalExclusionBuildItem removalExclusion() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't really like the name of this build item. I also don't think it should be necessary for beans added through AdditionalBeanBuildItem.

I think something like UsedBeanBuildItem would be better, the current one feels a bit like a double negative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is necessary for AdditionalBeanBuildItem - extensions do add many additional beans but these beans are not always needed at runtime.

UsedBeanBuildItem does not sound quite right to me. Hm, maybe something like UnremovableBeanBuildItem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Take the ConfigProducer as an examle of AdditionalBeanBuildItem that could be removed.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe AdditionalBeanBuildItem should have a 'removable' parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's exactly what I'm working on right now ;-)


@BuildStep
public BeanRemovalExclusionBuildItem removalExclusion() {
return new BeanRemovalExclusionBuildItem(new BeanClassAnnotationExclusion("javax.ws.rs"));
Copy link
Member

Choose a reason for hiding this comment

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

I also don't think this should be necessary, IMHO if a bean is added via an annotation specified in BeanDefiningAnnotationBuildItem then I don't think we should be removing 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.

Hm, this case is a little bit different and I agree that we should probably register UnremovableBeanBuildItem for BeanDefiningAnnotationBuildItems automatically.

- ported from Weld
- it is enabled by default
- resolves #540
@mkouba mkouba force-pushed the issue-540-removeunusedbeans-next branch from 986b103 to e5720eb Compare January 18, 2019 08:39
@mkouba
Copy link
Contributor Author

mkouba commented Jan 18, 2019

@stuartwdouglas Both AdditionalBeanBuildItem and BeanDefiningAnnotationBuildItem now have removable parameter. By default, it's true for beans and false for annotations.

BeanRemovalExclusionBuildItem was renamed to UnremovableBeanBuildItem.

I've also rebased the branch.

/**
* This build item is used to specify additional bean classes to be analyzed.
* <p>
* By default, the resulting beans should be removed if they're considered unused as described in {@link ArcConfig#removeUnusedBeans}.
Copy link
Member

Choose a reason for hiding this comment

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

Minor issue, but 'should be removed' is confusing, it should say that they are eligible for removal if they are considered unused and removal is enabled

Copy link
Member

Choose a reason for hiding this comment

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

'may be removed' would be better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. You know my english is cumbersome ;-)

@mkouba mkouba force-pushed the issue-540-removeunusedbeans-next branch from ef2bfdb to 2afc248 Compare January 18, 2019 09:36
@mkouba
Copy link
Contributor Author

mkouba commented Jan 18, 2019

@stuartwdouglas Anything else to add/improve?

@mkouba
Copy link
Contributor Author

mkouba commented Jan 18, 2019

Time is up I'm going to merge this ;-)

Feel free create new issues if you find something important...

@mkouba mkouba merged commit f2a1933 into quarkusio:master Jan 18, 2019
tsegismont added a commit to tsegismont/quarkus that referenced this pull request May 19, 2020
tsegismont added a commit to tsegismont/quarkus that referenced this pull request May 19, 2020
tsegismont added a commit to tsegismont/quarkus that referenced this pull request Jun 9, 2020
FroMage pushed a commit to tsegismont/quarkus that referenced this pull request Jun 11, 2020
tsegismont added a commit to tsegismont/quarkus that referenced this pull request Jun 17, 2020
johnaohara pushed a commit to johnaohara/quarkus that referenced this pull request Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants