ImageLoad speed

I've noticed that while using ImageLoad, I get a pretty big change in how long it takes to run if I load the same image more than once, even after deleting the image in between loads. 

Function load()
    Variable ref = startMSTimer
    String path = "MyImage.tif"
    ImageLoad/O/T=tiff/S=0/BIGT=1/C=-1/Q/LR3D path
    printf "%g seconds\r", (StopMSTimer(ref)/1e6)
End

On first run, I can load a 158 MB image stack into a 3D wave in 2.37 seconds. After deleting the image from the data browser, the code only takes 0.38 seconds to load the image. This is similar to the time it takes if I don't delete the image in between runs, an improvement which I thought was due to the reduced overhead of not needing to make the output wave. Where does the speed improvement come from after I've already loaded (but then deleted) the image from the data browser?

Just to make sure: Your code snippet does not include the full path to the file. Do you select the image from a file selection dialog? This selection process will be added to your final time. Otherwise, I cannot really reproduce your problem here on Windows 8.1 using Igor 9.01, and using the full path to the file. I get consistently 0.22-0.27 s for a 50 MB file when overwriting or deleting the wave in-between. Sometimes I get unfavorable 0.38-0.40 s. I guess some other windows process is interfering then. Let us know which OS and Igor version you are using, and whether or not you are providing the full path to the file in your real-world application.

That was more of a placeholder - when I'm running it for real it has the full path to the tif file as a string input. The snippet reproduces the problem on its own, but the normal context is running that line within a load function I have that operates from a GUI. It's coming from an external SSD if that matters. I'm on Igor 8.05 with Mac OS 12.5.1. 

Hello Ben,

Depending on your hardware, the extra time on the first run could be just memory allocation for the initial target wave.  You can test this theory by keeping the first wave around when you read the second image.

A.G.

Hi A.G.,

So if I load the image in, then delete it from the data browser, and reload in the same image, I'm still getting the much faster load time on the second load, despite the target wave being deleted from Igor. I can actually start a new experiment file or even completely restart Igor for the second load (so no wave ever existed in the data browser prior to the load) and it retains its fast speed. This occurs for loads from my external SSD and straight from my desktop.

Hi Ben,

Without access to the hardware and some experimentation, I can only guess.  Normally, 158MB should not be a significant amount of RAM on a modern machine and therefore the time to clear and allocate a contiguous block of this size should not be on the order of seconds.  It is also possible that your disk/SSD has some smart caching so that after your first read there are faster reads from similar/nearby locations.  In the old days, you would also take into account the time for the processor to load the TIFF library.

Other considerations have to do with the fact that a TIFF stack is read one image at a time.  Early TIFF libraries suffered from bad logic when it came to loading stacks (the IFD was read O(n^2) times).  If your file format is not BIGTIFF you may want to try to load your data using /BIGT=0.  This uses Igor's internal code which is more efficient in loading stacks.

 

AG