0

I am building a JavaFX-Application. I know that it's using reflection, and that reflection might be not so fast as when i would build my UI in the code.

So,

  1. How can I design my controller to keep the overhead, that is caused by reflection as small as I can?
  2. Does the size of the method with/without @FXML-Annotation matter?
  3. Is there any difference, when I call another method without @FXML in my controller-method? Like:
    @FXML
    public void handleButtonClick(){
       doStuff();
    }
    public void doStuff(){
       //implement the logic
    }
  1. And if I do so, should I implement these methods in the controller class, or in another class?

P.S. I'm sorry for so many questions at once, but i found those specific things nowhere in the internet :(

Yan_Yan
  • 67
  • 7
  • 1
    Have you experienced slowness in your app? Generally it is not a good idea to try to optimize things before they require it. It can increase complexity of code with a corresponding payoff. If you are experiencing slowness a good place to start investigating is with a profiler. – SephB Dec 16 '19 at 17:36
  • I will say, from my own experience profiling, setting style of tableview cells (to change colors) was by far the most expensive thing in my app. Creating a custom cell class that could handle changing its color without using styles fixed that issue. – SephB Dec 16 '19 at 17:43
  • 1
    Usually it's only the implementation itself that makes your ***controller*** slow. Calling a method does introduce some overhead, but it's not a significant one; unless you're calling those methods with a frequency that would freeze your app anyways, you'll probably not see any difference. If you're asking about what makes the fxml loading process slow: There are A LOT of factors (speed of the input stream providing the fxml, speed of the classloader, number of classes used in the fxml, size of the fxml, size of the controller class, ect. (size refering to number of members))... – fabian Dec 16 '19 at 20:19
  • Perhaps a duplicate of [Is there a way to compile / load fxml files faster?](https://stackoverflow.com/questions/24077524/is-there-a-way-to-compile-load-fxml-files-faster-and-only-one-time-and-not-at) – jewelsea Dec 16 '19 at 22:55
  • use a profiler instead of assuming .. – kleopatra Dec 16 '19 at 23:00

1 Answers1

0
  1. Keep any processes not related to the UI out of the main thread.

  2. No

  3. No

  4. If it makes sense from a design perspective.

That is no magic button you can click to make your app perform well. Worrying about these type of things at the start of a project will lead to a project that is difficult to manage. Instead, just dive in and don't be afraid to refactor if you think of a better approach or experience problems.

When you do inevitably run into problems don't be afraid to step into the JavaFX code with the debugger. That is the best way to learn about the internals of a framework.

SephB
  • 617
  • 3
  • 6
  • I guess there is one thing to warn any would be JavaFX user to avoid that is common in tutorials out there.... select bindings. There are some edge cases where they are useful, but in general are buggy and use reflection very poorly. – SephB Dec 16 '19 at 19:21