Jython plugin way faster from script interpreter than from Menu

imagej1
fiji
jython
script-interpreter
#1

I have a home-made plugin coded in Jython, which source code resides in Fiji.app>scripts>Plugins>MyPlugins such that I can call it like other plugin from the menu bar.

I can also drag and drop this code to open and run it in the script editor.

It is an object detector plugin and we found out that when we look for several objects the difference of speed is massive when the plugin is run from the script interpreter than from the menu bar:
it is much faster from the script interpreter!

From the menu bar, it is not slower because it is doing nothing, the computational load is high (fan speed increasing…:sweat_smile:)

And I’m not talking about a delay before the GUI pops up, it’s really the process itself which is slower eventhough it is the same piece of code and the same parameters (recalled by the persistence service).

I can’t share the code yet, but I was wondering what can be the reason for this.

One difference we observe is that when the plugin is executed from the menu bar, the call to the function MaximumFinder().getMaxima() seems to be slower: the progress bar shows “Analyzing maxima…” for long, while from the script editor it is quickly disappearing.

0 Likes

#2

Have you tried profiling the entire script or parts of it? It can be as simple as timing function calls and logging the times. This would give numbers to executions that “seem to be slower” and will probably help identify the culprit more easily.

1 Like

#3

I finally found out that it was the (numerous) print statements that were slowing down the execution when calling the plugin.

I guess that with the script interpreter they were directly displayed in the output field, while from the plugin they are actually not displayed if a console window is not open and end up somewhere making troubles ? :sweat_smile:

I would be curious to know if the IJ.log alternative would be faster.

1 Like

#4

Only if you use appropriate levels (or the console window is not open). I guess, as a lesson learned:

  1. Never print
  2. Always log
  3. Choose appropriate log levels

Somewhat related:

I also learned the hard way when first learning to program. I had std::cout (c++) in every iteration of a loop and my eta for my bachelor’s project was a year in the future. Removing the stdout reduced to a few seconds. :smile:

2 Likes