performance issues with for loop and imap/deque maxlen=0

Albert Cardona <[email protected]> Sat, 16 May 2020 00:09:22 +0100
Newsgroups gmane.comp.lang.jython.devel
Message-ID <CAJj13_-uTUQiV-oY3Cde9zxkzKygrLKsE28dfCodf_+0dV4+WA@mail.gmail.com>
Hi all,

I am seeing severe performance problems when looping over sequences
and invoking a single method on each element of the sequence, both
with a for loop and with an imap + deque maxlen=0 strategy. The
baseline is clojure, which is fully typed and compiled to bytecode.

The difference is staggering: 500x to 1000x (from about 1 second to 1
millisecond).

Here is a script that can run in Fiji:

https://github.com/acardona/scripts/blob/dev/python/imagej/tests/test_looping_performance_imglib2_setOne.py

The script creates an ImgLib2 image of width=512, height=512, depth=5,
of type unsigned byte, and then loops over all pixels to invoke the
method "setOne" on each pixel (pixels are presented as wrapped by an
UnsignedByteType object that offers the "setOne" method). There is an
underlying byte[] array of size 512*512*5 to the image.

Why the enormous difference? Anything that can be done to mitigate this issue?

Thank you very much.

Albert