1

I was wondering if there is a difference in the Wildcard Import handling between JavaFX and usual Java.

 

In Java there are no real negative impacts on using Wildcard Imports. You just have to keep namespaces in mind like mentioned here.

 

But what about imports in an FXML? Just heard that there could be an performance impact, but also heard that about usual Java which turned out as not true (AFAIK).

 

References to sources would be appreciated.

 

Thanks in advance!

Community
  • 1
  • 1
Jan
  • 1,004
  • 6
  • 23
  • 1
    I used [this repository](https://github.com/sialcasa/javafx-pitfalls) as base to make some performance tests (I have updated the test harness slightly) and as an avarage after 100 iteration: loading the FXML file containing wildcards is 3-4 times slower than loading the one without wildcards. – DVarga Nov 23 '16 at 13:00
  • Thanks you for your answer :) – Jan Nov 23 '16 at 13:10
  • Of course imports have on influence on performance of java code, since imports are used on compile time and there is no data corresponding to the imports in class files (fully qualified class names are used everywhere). **Compilation** could be a bit slower though... – fabian Nov 23 '16 at 13:45
  • That's what I expected also, so I was quite surprised about the results. 100 times 100 iterations and there is always a "significant" difference. Did not have time to dig the sources yet. – DVarga Nov 23 '16 at 14:05
  • 1
    @fabian Imports in *Java* code have no influence on performance. But FXML is parsed at runtime, so imports in FXML may influence performance, as the class name resolution is performed against the imported classes reflectively at runtime. I don't know how the import mechanism in FXML is implemented, but it's not hard to imagine using wildcard imports and having the `FXMLLoader` resolve them at runtime could be quite performance intensive. – James_D Nov 23 '16 at 14:32
  • @James_D I never had any doubts about that. However the OP seemed not 100% sure about the java imports... For loading the fxml imports the best performance for resolving the classes is `O(N*M)` where `N` is the number of wildcard imports and `M` is the number of classes used in the fxml that can only be found using one of the wildcard imports. – fabian Nov 23 '16 at 15:30

0 Answers0