pinterest / PINRemoteImage

A thread safe, performant, feature rich image fetcher
Apache License 2.0
4.01k stars 511 forks source link

Burst Animated Image speed of frame index search #523

Closed zhongwuzw closed 4 years ago

zhongwuzw commented 5 years ago

Currently, our frame index search algorithm time complexity for a GIF is O(N^2), we can burst it to O(N*logN), the time saving is distinct, for the example url like below, old algorithm needs 4.8ms, but new algorithm only need 0.038ms. Saving time for main thread.

    // test code
    for (int i = 0; i < animatedImage.frameCount; i++) {
        [self frameIndexAtPlayHeadPosition:_durations[i]];
    }

Old: 0.0048750638961791992 s
New: 0.000038027763366699219 s

https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562863518519&di=89f96479d2f9f85b01af61e281903af0&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20170110%2Fb56b87be5f174eca81f9d06116aa1968.jpg

ghost commented 5 years ago

🚫 CI failed with log

ernestmama commented 5 years ago

Would you mind updating the CHANGELOG.md?

zhongwuzw commented 5 years ago

@ernestmama Done!

ghost commented 5 years ago

🚫 CI failed with log

ghost commented 5 years ago

🚫 CI failed with log

ghost commented 5 years ago

🚫 CI failed with log

ghost commented 5 years ago

🚫 CI failed with log