Skip to content

Replace reflection with MethodHandle access in projection#561

Open
He-Pin wants to merge 2 commits into
mainfrom
refactor/replace-reflection-with-methodhandles
Open

Replace reflection with MethodHandle access in projection#561
He-Pin wants to merge 2 commits into
mainfrom
refactor/replace-reflection-with-methodhandles

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 6, 2026

Copy link
Copy Markdown
Member

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.

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.
@He-Pin He-Pin changed the title refactor: replace projection reflective access with handles Replace reflection with MethodHandle access in projection 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
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