Replace reflection with MethodHandle access in projection#561
Open
He-Pin wants to merge 2 commits into
Open
Conversation
Motivation: Reduce direct reflection in projection tests and gRPC internals while preserving existing runtime behavior. Modification: Use MethodHandles for H2 driver class lookup and initialization, protobuf parser access, and Scala companion construction paths. Result: Projection dynamic access paths avoid Class.forName and reflective invocation in the touched modules.
pjfanning
reviewed
Jul 6, 2026
Motivation: Address PR review feedback that repeatedly calling MethodHandles.publicLookup() has unnecessary overhead while keeping the MethodHandle-based parser resolution behavior. Modification: Store a shared public Lookup for Java protobuf parser discovery and cache parser MethodHandles with a ConcurrentHashMap putIfAbsent pattern to avoid non-atomic TrieMap getOrElseUpdate lookup races. Result: ProtoAnySerialization reuses the public lookup and aligns parser handle caching with the existing ConsumerFilterStore MethodHandle cache style. Tests: - scalafmt --mode diff-ref=origin/main - scalafmt --list --mode diff-ref=origin/main - sbt "grpc-test / Test / testOnly org.apache.pekko.projection.grpc.internal.ProtoAnySerializationSpec" - sbt "jdbc / Test / testOnly org.apache.pekko.projection.jdbc.JdbcProjectionTest org.apache.pekko.projection.jdbc.JdbcOffsetStoreSpec" - sbt "jdbc / Test / testOnly org.apache.pekko.projection.jdbc.H2JdbcOffsetStoreSpec" - sbt "jdbc-int-test / Test / testOnly org.apache.pekko.projection.jdbc.JdbcProjectionSpec" - sbt "examples / Test / compile" - git diff --check - qodercli stdout review: No must-fix findings (/tmp/project-qoder-review-2.log) References: Refs #561
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
Reduce direct reflection in projection tests and gRPC internals while preserving existing runtime behavior.
Modification:
Use MethodHandles for H2 driver class lookup and initialization, protobuf parser access, and Scala companion construction paths.
Result:
Projection dynamic access paths avoid Class.forName and reflective invocation in the touched modules.