DarkStarSword / 3d-fixes

Stereoscopic 3D fixes using Helix mod & 3DMigoto
105 stars 126 forks source link

Pad() is slow for large exports. #32

Closed SinsOfSeven closed 1 month ago

SinsOfSeven commented 4 months ago

https://github.com/DarkStarSword/3d-fixes/blob/c69e8cc1734b41f0e0ef5db38dfb7b8bdb35f367/blender_3dmigoto.py#L291-L294

The current pad() function is very for very large exports. We did some profiling with cProfiler, and investigated some alternatives to the Concatenate Operator. We found this was a good alternative.

    def pad(self, data, val):
        padding = self.format_len - len(data)
        assert(padding >= 0)
        data.extend([val]*padding)
        return data

The profiler says this is only about 50% faster for this individual execution, but it seems to improve the time overall quite a lot more. As this only really shows in large exports as a major slowdown, it wasn't really necessary, but we ended up doing a lot of exports while developing some new tools and it became bothersome.

We just wanted to report back to you, We were actually hoping for a much larger speedup when we started, but we couldn't think of a better way to generate the IBs or loop over the custom properties. This was the best we could do without taking the dive into a custom c/c++ implementation (which was honestly beyond our depth anyways for the blender API).

Thanks for this awesome tool!

DarkStarSword commented 4 months ago

Thanks for looking into this :)

I take it self.format_len is a cached version of format_components(self.Format)? I expect that will be where the majority of the speedup comes from here.

If you can put this in a pull request I'll be happy to merge it :)