Image Loading Performance

My coworker and I developed a project on our mac laptops and I am now moving it over to what I was hoping would be its final install location - on a quad core linux box. There is a huge performance problem and I am hoping for some advice on pin pointing the problem.

On my 16 gb 10.11 mac laptop it is running at 30 fps and then when I move it over it is running at 9 fps. I know exactly what line of code is causing it:

frameImage.load(activeImages->at(loopLevelFrame));

This line is loading an image from a list of file paths every frame. I am new at sourcing components and installing graphics drivers. Are any of my specs red flags? Should I dive into trying out installing other graphics card drivers? I have already tried loading all the images in setup, but there are too many (9000).

Thanks in advance for any help and sorry if this isn’t exactly an OF problem.

Here are all my specs:
System Hardware: Processor: AMD Athlon X4 840 Quad Core @ 3.10GHz (4 Cores),
Motherboard: MSI A88XI AC (MS-7913) v1.0,
Chipset: AMD Family 15h ,
Memory: 16384MB,
Disk: 240GB Western Digital WDS240G1G0A-,
Graphics: AMD Radeon RX 470/480 4096MB,
Ubuntu 17.04

(Also the computer is partitioned - half windows and half linux)

Hi! How much do all the images occupy? If they fit in a RAM disk you could try using one.

Assuming the images are JPG, and that each image takes <1Mb, 9000 x 1 Mb means 9 Gb. Not sure how much RAM you need to run your system, but since you have 16Gb you could create a 9Gb ram drive, put all images in that drive, and make your program load them from the new location. It will not work if your images are much heavier than that (because you won’t have enough RAM to load them in).

Note that the difference between using this technique and loading all images into OF is that OF will uncompress the images once loaded. So a 1920x1080 RGB image, even if the JPG occupies 1Mb, once in memory it takes at least 6Mb (1920x1080x3).

It seems like your 240GB drive is an SSD, so it should not be much slower than on the Mac side. Do you have the right graphics drivers installed? Are you loading the images from the SSD or from somewhere else? Do you load them from the Linux partition or the Windows partition?

One more question: how many milliseconds does it take to run that .load() line on each OS?

1 Like

Thanks for your response! The images are 200 kb a piece, so the RAM drive would certainly be an option, but I’d also like to get to the bottom of why it is loading so slowly considering my specs. The images are loading from the linux partition from the SSD. One image is loading at ~100 ms whereas it’s taking ~21 ms on my mac.

Unfortunately I don’t have access to the computer till Monday (the ssh isn’t set up just yet), but I am going to check up on the graphic driver details then and report back. I did not install the OS / set up the bios myself and I don’t know what drivers were installed during that process.

I did some tests and I got these conclusions:

  • JPEG image file size affects load/decode time, but the relationship is not linear. A ~1800Kb JPG takes 2,4x longer than a ~100Kb JPG.
  • PNG images loads twice as fast as a JPG images of the same file size. Unfortunately PNG images are likely to have higher file size.
  • JPEG, PNG and TIFF image loading times do not benefit much from being stored in a RAM disk (almost no difference).
  • TIFF images load between 2 and 4 times faster than JPEG images, 2 times faster than PNG images (looking at pixels per ms.).
1 Like

Although I didn’t use it yet I would highly recommend ofxTurboJpeg, I used the turboJpeg library once with Processing and it improved sometime up to 300% jpeg file loading .
So I guess a ramdisk + turbojpeg would work great.

1 Like

Hi,
if you are reusing the images within your app, I mean reuse in several time instances, you can load all the images into a vector and load at startup. Then use an ofTexture and upload to it the needed pixels using ofTexture::loadData(...)

If this is not an option write all the images to disk uncompressed. Make a small of app that opens the images and writes to disk the raw pixel data. Then make a function to open this raw data into an ofImage or ofPixels object. This is super fast,specially if you have an SSD, but it comes at a much higher disk space usage and a lot of disk reading. I’ve done this before but cannot find the code for it, although there’s an addon for it, which I haven’t used but it will probably be helpful.


this other one might also work

best

2 Likes

Thank you everyone for your suggestions!

Unfortunately the program completely freezes up when I attempt to load all the images into vectors at the beginning, so I’ve focussed on decreasing loading time so I can load the images as I need them.

I’ve updated the graphics card following these instructions and enabling it through the additional drivers menu. Doing that gave me a very small performance increase of about ~15 milliseconds (taking it down to ~85 milliseconds per image). Using ofxturbojpeg created a significant increase in speed. Using that add-on each image takes 20- 30 milliseconds to load. So now the program is running at ~ 30 fps, which is up to the level it needs to be! I also tried loading the images as PNGs, TIFFs, and from a ramdisk. The best speed result was using ofxturbojpeg with Ramdisk (~ 13 - 20 millis). Although Ramdisk improved the results, it isn’t persistent so I would have to write extra scripts to create that on boot.

I am still confused as to why there is such a big performance gap between the mac and the linux box to begin with. My current theory is that I am on ubuntu 17.04 but the AMD graphics card driver is intended for ubuntu 16.04. If anyone has any other theories I’d love to hear them!

I have encountered a new error when I left the computer running over night that suggests there is an issue with graphics card or driver:

migratoryBirdViz_debug: /home/foreman/sources/drm/andgpu/andgpu_internal.h:218: update_references: Assertion 'atomic_read(dst) 0' failed.

@arturo might have a better insight about what´s going on in linux.
cheers

when loading images the bottleneck is usually on the drive. the drive you mention seems to be an ssd so not sure why it would be so slow but try to run some speed tests on it and on your mac to see what’s the difference

I wonder if it would improve to make a movie from all of the pictures and then access them with the frame number of the desired picture, ofxHapPlayer is fast at this and has a good quality, but it compile only in 32bits.