Frommi / miniz_oxide

Rust replacement for miniz
MIT License
168 stars 48 forks source link

inflate::core::init_tree() is slow #82

Closed Shnatsel closed 1 year ago

Shnatsel commented 4 years ago

When opening small-ish images with png crate more than 50% of time is spent in inflate::core::init_tree function. This makes png crate 3x slower than spng according to spng crate benchmarks. Using larger images closes the gap.

Sample image demonstrating the issue (25Kb): https://github.com/aloucks/spng-rs/blob/master/spng/tests/test-002.png

Profile: https://profiler.firefox.com/public/d87cd7f7fde83f8b4ddd2ee3e5d0b4f20312ee42/flame-graph/?globalTrackOrder=0-1-2-3-4&localTrackOrderByPid=27730-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40~27839-0~27840-0-1-2-3-4~27841-0~27847-0-1-2-3-4~&thread=42&timelineType=stack&v=4

Shnatsel commented 4 years ago

The difference is not large in absolute terms - it's 3ms with png vs 1ms with spng. But that could still be noticeable in a networked setting (2 more ms to establish a connection) or when processing a lot of small images e.g. in machine learning workloads.