GIF Loader

Monkey Forums/Monkey Code/GIF Loader

CopperCircle(Posted 2015) [#1]
Hi, here is a .gif loader written in pure MonkeyX, it needs more optimisation and is slow loading large gifs on Android...!

https://github.com/CopperCircle/GIF-Loader


ziggy(Posted 2015) [#2]
That's very nice!


Beaker(Posted 2015) [#3]
Nice. What is the major bottleneck do you think?


CopperCircle(Posted 2015) [#4]
Processing the binary is slow, I am not sure what would be the best way to improve it.


muddy_shoes(Posted 2015) [#5]
I've had a tinker and got a bit of a speed-up. It's about ten times faster on my Android phone than it it was. The major chunk left is in all the data copying for the decompression tables and some GC activity that'd probably need a more significant rewrite to tackle. Here's the altered gifreader file.




CopperCircle(Posted 2015) [#6]
Thanks muddy_shoes :)


muddy_shoes(Posted 2015) [#7]
I've been working on this a bit more. I noticed that it was pretty much unusable for large GIFs on anything with memory limitations as it decoded the whole GIF. To improve matters, I've made some further changes:

* On loading it now just processes all the header information and stores indices to the encoded image data.
* On playback it decodes only the required frames and decodes to a "canvas" array of ints, which is then written in one pass to a single image for rendering.
* The decoder now uses a one dimensional array for the decode table values with two arrays for indices and entry lengths to avoid all the array construction involved in the array of arrays solution.

I'm still working on it, both to try and improve the speed further and to sort out a more usable API/generally tidy it up, but if you're using the code you had you might want to take a look at my fork to see if the changes help you out, particularly on Android. Loading is under half a second on my phone for even the largest example GIFs you had and they play back fully, if a bit slowly. https://github.com/ootsby/GIF-Loader

Edit: It's worth noting that a fair chunk of the remaining Android performance issues are down to the terrible texture binding performance of the standard mojo code that's been known about for years.


CopperCircle(Posted 2015) [#8]
That's a great improvement! I the android binding performance is increased changing line 118 in mojo.android.java from Bind() to Bind2().
Thanks.


muddy_shoes(Posted 2015) [#9]
Yeah, there's also a simple two-line drop-in in the original Bind that improves matters. Just flagging that the standard distributed code is a problem for this application.

I was thinking of writing up an optimisation/refactoring case-study blog post or two based on this. Would you mind?


CopperCircle(Posted 2015) [#10]
No go ahead, I am always happy to build something in Monkey as a proof of concept and it is great when others get involved and improve it.