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 micro optimizations #18567

Merged
merged 1 commit into from
Jul 13, 2021
Merged

ArC micro optimizations #18567

merged 1 commit into from
Jul 13, 2021

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Jul 9, 2021

  • trim list of removed Beans
  • trim Resource reference providers
  • trim active Beans
  • do not use LinkedList
  • share qualifier annotation literals and Type instances in the
    generated ComponentsProvider

Co-authored-by: Sanne Grinovero sanne@hibernate.org

@quarkus-bot quarkus-bot bot added the area/arc Issue related to ARC (dependency injection) label Jul 9, 2021
@mkouba
Copy link
Contributor Author

mkouba commented Jul 9, 2021

I also tried to do some inexact and naive tests with the hibernate-orm-quickstart where exactly 50 beans is removed by default:

  1. Build the project with the relevant quarkus version
  2. Run the app
  3. Send an HTT GET to localhost:8080/fruits
  4. Run the GC several times
  5. Dump the heap and calculate the retained size of ArcContainerImpl#removedBeans

I tested the main branch, Sanne's PR and this PR:

Branch Approx. retained size of ArcContainerImpl#removedBeans
main 16 KB
the other PR 11 KB
this PR 8 KB

@mkouba
Copy link
Contributor Author

mkouba commented Jul 9, 2021

@Sanne It would be great if you could run your tests again and confirm/disprove my findings. FYI I cherry-picked 5 of your commits and only left out those that modified the RemovedBean and RemovedBeanImpl classes. Thanks!

@mkouba mkouba requested review from manovotn, Sanne, geoand and Ladicek July 9, 2021 14:11
Comment on lines -21 to +22
return Collections.emptySet();
return Set.of();
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know this was actually better

Copy link
Member

Choose a reason for hiding this comment

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

I had never seen this method :) Seems it's new in Java 9.
But also it's a constant in both cases apparently... I suppose you prefer it because of style Martin ?

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's not better, I just wanted to be consistent here... ;-)

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

LGTM

return Set.of(set.iterator().next());
case 2:
Iterator<T> it = set.iterator();
return Set.of(it.next(), it.next());
Copy link
Member

Choose a reason for hiding this comment

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

hum, Set.of( ) produces an object of 24 bytes, while Collections.singleton 16 ,,. previous was 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.

So I suppose you mean the java.util.ImmutableCollections.Set12 which is used for both a singleton and a doubleton.

  1. Previously, we did not use a specialized set for a doubleton, which is a pity because in CDI doubletons are quite common.
  2. I don't think it's reasonable to sacrifice the consistency for 8 bytes...

this.description = description;
this.types = CollectionHelpers.toImmutableSmallSet(types);
this.qualifiers = qualifiers != null ? CollectionHelpers.toImmutableSmallSet(qualifiers)
: Qualifiers.DEFAULT_QUALIFIERS;
this.qualifiers = CollectionHelpers.toImmutableSmallSet(qualifiers);
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 understand this, it looks lik you rather prefer to always allocate a new wrapping collection? I was trying to avoid those when not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note really, the qualifiers set is always null for default qualifiers and CollectionHelpers.toImmutableSmallSet() returns null for null param.

@@ -387,16 +387,26 @@ void addComponentInternal(ObserverInfo observer) {
private final ResultHandle removedBeansHandle;
private final ClassOutput classOutput;
private ResultHandle tccl;
// Shared annotation literals for an individual addRemovedBeansX() method
private final Map<AnnotationInstanceKey, ResultHandle> sharedQualifers;
Copy link
Member

Choose a reason for hiding this comment

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

Is that worth 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.

I think it is. For example, because of SR Config almost every app will have ~ 30 removed beans with the @ConfigProperty qualifier, which in turn results in a new AnotationLiteral instance stored in the removedBeans list. This way, we can reduce the number of annotation literal instances to 2 (for the hibernate-orm-quickstart).

@gsmet
Copy link
Member

gsmet commented Jul 12, 2021

I think we should merge this. We can still improve later on top of this if needed.

@mkouba mkouba marked this pull request as ready for review July 12, 2021 08:24
- trim list of removed Beans
- trim Resource reference providers
- trim active Beans
- do not use LinkedList
- share qualifier annotation literals and Type instances in the
generated ComponentsProvider

Co-authored-by: Sanne Grinovero <sanne@hibernate.org>
@mkouba mkouba force-pushed the arc-removed-beans-opt branch from 26460c5 to ffa6e30 Compare July 12, 2021 09:22
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 12, 2021

This workflow status is outdated as a new workflow run has been triggered.

🚫 This workflow run has been cancelled.

Failing Jobs - Building 26460c5

⚠️ Artifacts of the workflow run were not available thus the report misses some details.

Status Name Step Test failures Logs Raw logs
Gradle Tests - JDK 11 Windows Build ⚠️ Check → Logs Raw logs
JVM Tests - JDK 11 Build Test failures Logs Raw logs
JVM Tests - JDK 11 Windows Build Test failures Logs Raw logs
JVM Tests - JDK 16 Build Test failures Logs Raw logs
MicroProfile TCKs Tests Verify ⚠️ Check → Logs Raw logs
Native Tests - Cache Build ⚠️ Check → Logs Raw logs
Native Tests - HTTP Build ⚠️ Check → Logs Raw logs
Native Tests - Messaging1 Build ⚠️ Check → Logs Raw logs
Native Tests - Messaging2 Build ⚠️ Check → Logs Raw logs
Native Tests - Misc1 Build ⚠️ Check → Logs Raw logs
Native Tests - Misc2 ⚠️ Check → Logs Raw logs
Native Tests - Misc3 ⚠️ Check → Logs Raw logs
Native Tests - Misc4 ⚠️ Check → Logs Raw logs
Native Tests - Security1 Build ⚠️ Check → Logs Raw logs
Native Tests - Security2 Build ⚠️ Check → Logs Raw logs
Native Tests - Security3 Build ⚠️ Check → Logs Raw logs
Native Tests - Spring ⚠️ Check → Logs Raw logs
Native Tests - Windows - hibernate-validator ⚠️ Check → Logs Raw logs
Native Tests - gRPC ⚠️ Check → Logs Raw logs

Full information is available in the Build summary check run.

Test Failures

⚙️ JVM Tests - JDK 11 #

📦 extensions/arc/deployment

io.quarkus.arc.test.autoproduces.AutoProducerMethodDisabledTest. - More details - Source on GitHub


⚙️ JVM Tests - JDK 11 Windows #

📦 extensions/arc/deployment

io.quarkus.arc.test.autoproduces.AutoProducerMethodDisabledTest. - More details - Source on GitHub


⚙️ JVM Tests - JDK 16 #

📦 extensions/arc/deployment

io.quarkus.arc.test.autoproduces.AutoProducerMethodDisabledTest. - More details - Source on GitHub

@mkouba
Copy link
Contributor Author

mkouba commented Jul 13, 2021

The PR is ready now...

@gsmet gsmet merged commit 05ab2b6 into quarkusio:main Jul 13, 2021
@quarkus-bot quarkus-bot bot added this to the 2.1 - main milestone Jul 13, 2021
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.

4 participants