Skip to content

Simplify the 'factory' MethodHandle signatures to drop 'dependency' types from them #1889

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

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

copybara-service[bot]
Copy link

Simplify the 'factory' MethodHandle signatures to drop 'dependency' types from them

I thought modeling native types would be better but on reflection it just adds complexity for little gain. So turn all generated factories into (InternalContext)->Object types. This eliminates a bunch of asType adapters and should improve linkage performance a bit (not that this is a huge concern), but the major benefit is just simplicity.

Performance is an interesting question here. In principle we are just adding 'no op' cast to Object on constructor and provides method invocations, and then checkCast instructions at constructor and method parameter injection points. So the waste is those extra cast operations. However, in the JVM those are nearly free (simple pointer check, can often be elided as part of normal invocation type checking). So my guess is that this is a no-op performance wise. Some limited benchmarking of @Provides and @Inject constructors bears this out.

…ypes from them

I thought modeling native types would be better but on reflection it just adds complexity for little gain.  So turn all generated factories into `(InternalContext)->Object` types.  This eliminates a bunch of `asType` adapters and should improve linkage performance a bit (not that this is a huge concern), but the major benefit is just simplicity.

Performance is an interesting question here.  In principle we are just adding 'no op' cast to `Object` on constructor and provides method invocations, and then `checkCast` instructions at constructor and method parameter injection points.  So the waste is those extra `cast` operations.  However, in the JVM those are nearly free (simple pointer check, can often be elided as part of normal invocation type checking). So my guess is that this is a no-op performance wise.  Some limited benchmarking of `@Provides` and `@Inject` constructors bears this out.

PiperOrigin-RevId: 740791709
@copybara-service copybara-service bot merged commit 17aa84c into master Mar 26, 2025
1 check passed
@copybara-service copybara-service bot deleted the test_740497045 branch March 26, 2025 16:13
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.

1 participant