-
Notifications
You must be signed in to change notification settings - Fork 425
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
Running annotation-based picocli applications without runtime reflection #539
Comments
Hi @remkop, is there any progress on this? Do you maybe have an estimation on when you would get around to implementing this? |
Hi @kristofdho I am not currently working on this and I don't see myself working on this in the near future. So I cannot give any estimate. However, this message that was posted on the picocli mailing list may be relevant, so let me copy it here: On Tuesday, July 6, 2021 at 9:14:03 PM UTC+9 [email protected] wrote:
I currently have very little time to spend on picocli, but if this is something you want to work on, we can look at bringing this to production quality and integrating this into the picocli project somehow. |
@remkop Thank you for the quick reply. For now our best option would probably be writing a feature that programatically registers the required reflection configuration based on reachabillity hooks. However, could you shed some light on when the reflective lookup calls happen? The |
@kristofdho Reflection happens at two times:
An annotation processor could avoid both usages: the processor could generate code that creates the model. The IGetter and ISetter for each option and positional parameter could simply set the annotated field value (or invoke the annotated method) programmatically without reflection. The It should be possible to reuse a single |
May I ask a possibly stupid question - has anyone profiled PicoCLI startup time to determine that reflection actually is the problem? I'm a bit disturbed by the comment above saying that even with compile-time generated specs, startup time didn't improve much. Why would that be? Where is the time actually going? |
@mikehearn That is a good question. I personally have not spent time profiling. I believe some others have, notably here: #1377
Can you link to that comment? I cannot find it. |
|
The annotation processor implemented in #500 can create a
CommandSpec
model at compile time.One use case for an annotation processor like this is to generate source code at compile time that would allow picocli-based applications to run without runtime reflection.
This ticket is to explore some ideas for achieving that.
One idea is to generate code (actually modify an existing annotated class) to implement an interface, where a method in this interface generates a
CommandSpec
model. Picocli needs to be modified to not perform reflection when the user object implements this interface, and instead call the interface method to obtain theCommandSpec
.Example input:
Example output of annotation processor:
Lombok does something similar: it inserts accessor code into an existing class for fields annotated with
@Getter
and@Setter
.The way Lombok does this is by using internal APIs from Javac and the Eclipse compiler.
The text was updated successfully, but these errors were encountered: