Skip to content

Conversation

dmlloyd
Copy link
Member

@dmlloyd dmlloyd commented Apr 25, 2025

Introduce two features:

  • List/Set/Map plain constants (good for less than ~30 elements)
  • External resource-backed constants for List/Set/Map of String specifically (no other constant types)

The constants are implemented in terms of condy.

The plain constants are a bit greedy with the constant pool. The amount of slots will amortize towards one slot per entry if enough are used, but for smaller collections it could be 2-3 slots per entry. Nevertheless these could be quite handy in certain circumstances where you have a small fixed set of, say, classes that you only use in one or two places and you don't want to go through the ceremony of setting up a field for it.

The resource-backed collections are unbounded in maximum size, however they will take up several constant pool slots (amortizing to 1 per collection if enough are used in one file).

@dmlloyd dmlloyd added the 2.x Issue applies to Gizmo 2.x label Apr 25, 2025
@Ladicek
Copy link
Contributor

Ladicek commented Apr 28, 2025

The plain constants are a bit greedy with the constant pool. The amount of slots will amortize towards one slot per entry if enough are used, but for smaller collections it could be 2-3 slots per entry. Nevertheless these could be quite handy in certain circumstances where you have a small fixed set of, say, classes that you only use in one or two places and you don't want to go through the ceremony of setting up a field for it.

The resource-backed collections are unbounded in maximum size, however they will take up several constant pool slots (amortizing to 1 or 2 per collection if enough are used in one file).

In other words, this means there's constant pool overhead in each class that uses this mechanism, due to condy, but it's fixed regardless of how many collections/elements are used. Right?

@Ladicek
Copy link
Contributor

Ladicek commented Apr 28, 2025

Looks reasonable on the first sight.

@dmlloyd
Copy link
Member Author

dmlloyd commented Apr 28, 2025

The plain constants are a bit greedy with the constant pool. The amount of slots will amortize towards one slot per entry if enough are used, but for smaller collections it could be 2-3 slots per entry. Nevertheless these could be quite handy in certain circumstances where you have a small fixed set of, say, classes that you only use in one or two places and you don't want to go through the ceremony of setting up a field for it.
The resource-backed collections are unbounded in maximum size, however they will take up several constant pool slots (amortizing to 1 or 2 per collection if enough are used in one file).

In other words, this means there's constant pool overhead in each class that uses this mechanism, due to condy, but it's fixed regardless of how many collections/elements are used. Right?

More or less. Each collection needs one constant pool entry for the collection itself (as of my most recent code). A certain amount of constant pool entries are used by the bootstrap method(s), but those only need to be generated once (per collection type) even if many collections are used in the same class. That's basically it.

@dmlloyd dmlloyd marked this pull request as ready for review April 28, 2025 16:47
@dmlloyd dmlloyd linked an issue Apr 28, 2025 that may be closed by this pull request
@@ -60,7 +99,7 @@ public abstract sealed class TypeCreatorImpl extends AnnotatableCreatorImpl impl
List<Consumer<BlockCreator>> postInits = List.of();
private List<Signature.ClassTypeSig> interfaceSigs = List.of();
private int flags;
private boolean hasLambdaBootstrap;
private int bootstraps;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think an EnumSet would work the same here, but we can keep it manual.

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.

Can't say I reviewed the condy bootstraps in detail, but overall LGTM.

@dmlloyd dmlloyd merged commit b939b05 into quarkusio:main Apr 29, 2025
1 check passed
@dmlloyd dmlloyd deleted the resources branch April 29, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issue applies to Gizmo 2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "resource constant"
2 participants