Skip to content
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

GIF export speedup #696

Merged
merged 7 commits into from
May 23, 2022
Merged

Conversation

novhack
Copy link
Contributor

@novhack novhack commented May 7, 2022

I looked into LZW compression code in the gifexporter addon and simplified it a little bit.

The result is as speedup of around 3.6 times.

Using Roroto's awesome splashscreen it went from 43,26 seconds to 11,96 seconds in the editor. Compiled version of Pixelorama goes from 34.5 to 9.3 seconds.

I did some tests with multiple animation files and gifs exported from 0.10 and exported from this changed version are identical according to "cmp -l"

I will eventually commit this also to the jegor's repository but it seems to be outdated at this moment.

I also commented the decompress function because it now needs a rewrite and is currently unused.

There are for sure more ways the speed the whole thing up but small steps...

@novhack
Copy link
Contributor Author

novhack commented May 7, 2022

Do not merge yet. I found a bug with big images which require quantization. They are exported as solid color gifs and I need to investigate.
EDIT: This issue is also present in 0.10-stable so it's probably not caused by this pull request and needs a separate issue.

@novhack novhack marked this pull request as draft May 7, 2022 22:28
@novhack novhack marked this pull request as ready for review May 7, 2022 22:38
@novhack
Copy link
Contributor Author

novhack commented May 8, 2022

I rewrote the add_image_data_block() function to have less looping. It shaves off only around 100ms from the export I test on but it hugely helps in a profiler where it was causing big spikes.

@novhack
Copy link
Contributor Author

novhack commented May 8, 2022

I am done with this PR for now. The next step would be to somehow speed up LSBLZWBitPacker.write_bits() function which gets called a lot but it already uses a lot of bithacks so there is not much room to work with.

current_code_size = new_code_size_candidate

return index_stream
#func decompress_lzw(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be best if we removed this method entirely instead of commenting it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to leave it as a reminder that it should be reimplemented with a proper gif import support but it's also possible to remove it.

@novhack
Copy link
Contributor Author

novhack commented May 12, 2022

The last commit helped to shave off a few hundred milliseconds. Now the export takes around 11.5 seconds.
The next step is to add bulk export - allow multiple frames to be processed at the same time in a thread pool.

Copy link
Member

@OverloadedOrama OverloadedOrama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@OverloadedOrama OverloadedOrama merged commit 86beee6 into Orama-Interactive:master May 23, 2022
OverloadedOrama added a commit to OverloadedOrama/godot-gdgifexporter that referenced this pull request Nov 28, 2023
This PR was originally made by @novhack for Pixelorama (Orama-Interactive/Pixelorama#696), but the changes weren't brought in this repo.

Note that I had to not keep the changes made in the `add_image_data_block()` method in exported.gd that the original PR had, because the resulting gif file seemed invalid. I'm not sure what the problem is, but even without this change the speedup is still there.

Using the default images of the project:
Gif exporting time before this PR: 1.70701233333333
Gif exporting time after this PR: 1.01357166666667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants