-
Notifications
You must be signed in to change notification settings - Fork 4
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
Pre-compile FXML to avoid reflection during runtime #23
Comments
Very interesting, but i doubt it is easily feasible. Anyway you got my curiosity and I'll have a look |
I'm not planning to create the Node structure statically, but generate a class that is instantiated at runtime with a method that does the actual building of the JavaFX gui. The method contains all the Pane pane = new Pane(), Label label = new Label(), pane.getChildren().add(label) statements that correspond to what the FXMLLoader usually does. You save the parsing of the FXML and most importantly, the runtime reflection. |
The problem I see is that the single entry point for this is
|
I will not use FXMLLoader directly (due to its use of reflection), but must ensure that the behavior of the parser and generated class is the same. So far I have a fairly good parser (using StAX) that builds a logical FXML document model, and a (so far) limited code generator, that handles the basic building of component hierarchy and setting of properties:
outputs
Several important things are missing:
The first, shouldn't be difficult, the second may be tricky as I want to reuse JavaFXBuilderFactory's logic. The last is most tricky, as I don't know how Quarkus does such things. |
Do you have a repo with your code ? |
I've now pushed some more code to the translator repository:
Together, this allows using FXML without runtime reflection. The snag is that code must instantiate the generated loader class, rather than the traditional FXMLLoader. The question is still: what does it take to integrate this into quarkus, for the best developer experience. |
I've had a look (before these updates) Not sure that using the maven plugin is the ultimate goal (the extension could handle all of that, I guess). I'll have a look when I get the opportunity to. Anybody with Quarkus extension knowledge is welcome ;) |
I tried to find examples of generating source code in a quarkus extension, but my impression is that they go directly to byte code (either explicitly, or using recording). The current translator has a java code model (AST like) that could just as well be used for generating byte code. Anyway, since I have no experience with quarkus extension, I found it was best to try to come as far as possible without quarkus-specific techniques, hence the source generator, annotation processor and maven plugin. A quarkus extension could continue from there or use the translator/processor more directly. |
I think this issue is a really good idea. |
The fxml-template-processor repo mentioned above has been extended with such a generator, maven plugin and sample project. Please take a look at the sample. I would love suggestions and help in properly integrating it with quarkus. |
Is there a project to write Fxml in other formats? such as Kotlin DSL, YAML etc. Personally I would like write it in Kotlin(UI layout and controller in one file) and discard the the fxml file. |
I was thinking that using a Any FXML modification would require a new build (not just launching the app) but start time would be fast and without reflection, I guess. |
It would be beneficial to move FXML parsing to build time, not just for speed, but particularly since it uses reflection. I've started a small project for generating Java source from FXML, so you instead of using an FXMLLoader can call a method on a pre-generated Java class.
The question is what is needed for it to work well with quarkus, e.g. should there be a drop-in replacement for FXMLLoader that uses the pre-generated class instead? We could use an annotation on an interface and generate an implementation that will be injected and that builds the corresponding GUI? E.g. something along the following:
Another thing to consider is FXML string templates (see prototype here: https://github.com/hallvard/fxml-template-processor).
I don't know much about Quarkus' annotation processing and build magic, so would like to open up a discussion about this in this issue.
The text was updated successfully, but these errors were encountered: