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
MINOR: [Java] Reduce enum array allocation #41533
base: main
Are you sure you want to change the base?
Conversation
@@ -38,6 +38,9 @@ | |||
* A {@link ConnectionConfig} for the {@link ArrowFlightConnection}. | |||
*/ | |||
public final class ArrowFlightConnectionConfigImpl extends ConnectionConfigImpl { | |||
private static final ArrowFlightConnectionProperty[] ARROW_FLIGHT_CONNECTION_PROPERTY_VALUES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) Maybe we can use a truly immutable type like EnumSet
+ Collections#unmodifiableSet()
instead of an array.
Could you open a new issue instead of using |
I'm curious -- did we observe a large number of allocations here? It looks to me like this is only called once-per-JDBC-connection. Perhaps this is a connection pooling scenario? We may want to optimize body of the noneMatch() call to use a case-insensitive TreeSet if this is called frequently (instead of searching linearly for each key as we're currently doing). |
I agree this is likely to be of greater benefit. I would argue that instead of using |
Yes, http/2 normalizes to lower-case headers so that would be best |
Rationale for this change
reduce Java object allocation
context: https://www.gamlor.info/wordpress/2017/08/javas-enum-values-hidden-allocations/
What changes are included in this PR?
cache ArrowFlightConnectionProperty.values() in a static variable.
Are these changes tested?
ArrowFlightConnectionConfigImplTest unit test passes.
Are there any user-facing changes?
no