4 ms·
I was hired by SONY at one point to help optimize a piece of video editing software that the outsourced team had created and could not figure out how to make it
by justinlloyd 4y ago
I was hired by SONY at one point to help optimize a piece of video editing software that the outsourced team had created and could not figure out how to make it a) go faster and b) use less RAM. This is back when 16GB was on the upper end of what workstation class machines could handle.
The desktop application, written in an early 2004-ish version of C# and .NET regularly brought the workstations to their knees and thrashed memory and pegged the CPU when large 1080p images were being loaded in or moved around.
Each RGBA image, stored as a PNG on the HDD, was loaded in, each RGBA 32-bit unsigned integer was unpacked into its attendant R, G, B, and alpha components into 32-bit unsigned integers themselves, which were then stored in an Int (boxed the native to a non-native type) which were then appended to a dynamically allocated at read time ArrayList. Deep copies were made of each image any time one of them was resized or manipulated, keeping the original untouched image in RAM in case it was needed. A copy of the image before transformation was stored on the Undo stack. And the 1080p working surface of the screen was super-sampled at 8x resolution to support defringing of images when layered. All stored as 8-bit RGBA components in boxed 32-bit integers in a dynamically allocated ArrayList.
- eckza 4y agoDon't leave us hanging - what did you _do?_ Did you fix this?
- Jorge1o1 4y agoNot the parent so I can’t tell you exactly what he did, but some suggestions: - The PNG specification contains plenty of information including width and length that allow you to use 2d arrays rather than ArrayLists - The RGBA 32bit integer doesn’t need to be unpacked.. you can just perform shifts and transformations of each of the 8bit channels. - If you do unpack, you should use native 8bit unsigned ints - You don’t need an unmodified copy.. that’s your file - Undo stack should contain deltas, not the whole image over and over again. Edit: formatting
- prewett 4y agoThe obvious thing to do would be to store the image in memory as just an array of 8-bit of native unsigned integers (RGBARGBARGBARGBA...) and see where that got you. I assume C# has the equivalent of a Java byte[], except that fortunately it is unsigned in C# instead of signed in Java. I expect that you would get quite a performance boost with just that.