-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buffer for use with InputStream #13
Comments
Yes! I was actually doing some profiling on that and the renderFrame() call is some what slow for what I'd expect from decoding a GIF frame. Finding a good leak safe / thread safe way of not re-allocing every time with this line from streamReadFun(): Could be a pretty good win. Also, it might be worth looking into this line: GetByteArrayElements can do one of two things:
I'm not actually sure we can control the behavior, but we CAN pass in a jbool pointer into GetByteArrayElements and see which it's doing. That'd be a nasty perf hit if it was doing the copy every time. |
Maybe cache the buffer in the userdata on GifFileType? |
So i tried 2 things:
Let me know what you think. If we can't come up with something better, I'd say it's still worth taking as it prevents a little GC thrashing. It's probably worth further investigating perf hits in renderFrame() as it still doesn't seem as performant as I'd expect. I think we could further optimize by providing a code path for passing a Java byte array instead of an InputStream. In the read func this would allow us to simply memcpy the range we are interested in directly from the jByteArray to the native mem. Rather than copying from the Stream to the buffer, and then from the buffer to the native mem. We'd need to emulate the file cursor/reset functionality on our own though. |
#14 included this optimization. |
I think it is good idea to make new |
Oh sorry I wasn't clear, yes that was my intention. |
I think there is no need to use memcpy since GetByteArrayRegion can copy bytes directly from java byte array to native memory. I've added direct byte[] support in f1ca293. |
Oh yeah I actually looked into GetByteArrayRegion when I was working on Either way it would certainly be better where ever we can use it.
|
OK, I've changed GetByteArrayElements to GetByteArrayRegion. |
Reading from stream was optimized, so I am closing this issue. |
Two changes related to this issue was made in d5d3a31:
|
Creating one reusable Java's byte array per GifDrawable instance will be more efficient than allocating new array in each
streamReadFun()
call.The text was updated successfully, but these errors were encountered: