From ecb399508c311225c68dd1be22c04dadd9a92969 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 16 Dec 2018 08:17:29 +1100 Subject: [PATCH] Tweak how std/lzw yields "short read" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a std/lzw performance regression (for gcc only, not clang), introduced in 33a4557 "Collect GIF's LZW data into larger batches". This commit restores the std/lzw performance, but it also makes the std/gif benchmarks worse. As LZW is not really used outside of GIF, this commit will immediately be followed by a rollback, but it is committed anyway so that we can refer to these numbers in the git log. name old speed new speed delta wuffs_lzw_decode_20k/clang 213MB/s ± 1% 205MB/s ± 1% -3.90% (p=0.008 n=5+5) wuffs_lzw_decode_100k/clang 359MB/s ± 1% 351MB/s ± 0% -2.14% (p=0.008 n=5+5) wuffs_lzw_decode_20k/gcc 189MB/s ± 0% 229MB/s ± 0% +21.37% (p=0.008 n=5+5) wuffs_lzw_decode_100k/gcc 223MB/s ± 0% 390MB/s ± 1% +74.77% (p=0.016 n=4+5) wuffs_gif_decode_1k_bw/clang 225MB/s ± 1% 229MB/s ± 0% +1.52% (p=0.008 n=5+5) wuffs_gif_decode_1k_color/clang 118MB/s ± 1% 118MB/s ± 1% ~ (p=0.841 n=5+5) wuffs_gif_decode_10k_bgra/clang 569MB/s ± 0% 565MB/s ± 0% -0.66% (p=0.008 n=5+5) wuffs_gif_decode_10k_indexed/clang 152MB/s ± 1% 150MB/s ± 1% -1.25% (p=0.008 n=5+5) wuffs_gif_decode_100k_artificial/clang 454MB/s ± 1% 459MB/s ± 0% +1.05% (p=0.008 n=5+5) wuffs_gif_decode_100k_realistic/clang 179MB/s ± 0% 178MB/s ± 1% ~ (p=0.222 n=5+5) wuffs_gif_decode_1000k/clang 180MB/s ± 1% 181MB/s ± 0% +0.79% (p=0.016 n=5+5) wuffs_gif_decode_anim_screencap/clang 951MB/s ± 0% 958MB/s ± 0% +0.66% (p=0.008 n=5+5) wuffs_gif_decode_1k_bw/gcc 238MB/s ± 0% 240MB/s ± 0% +0.91% (p=0.008 n=5+5) wuffs_gif_decode_1k_color/gcc 130MB/s ± 1% 127MB/s ± 0% -2.25% (p=0.008 n=5+5) wuffs_gif_decode_10k_bgra/gcc 537MB/s ± 1% 518MB/s ± 2% -3.59% (p=0.008 n=5+5) wuffs_gif_decode_10k_indexed/gcc 164MB/s ± 1% 157MB/s ± 1% -4.43% (p=0.008 n=5+5) wuffs_gif_decode_100k_artificial/gcc 454MB/s ± 2% 447MB/s ± 0% ~ (p=0.095 n=5+5) wuffs_gif_decode_100k_realistic/gcc 186MB/s ± 1% 179MB/s ± 1% -3.28% (p=0.008 n=5+5) wuffs_gif_decode_1000k/gcc 188MB/s ± 1% 182MB/s ± 0% -3.06% (p=0.008 n=5+5) wuffs_gif_decode_anim_screencap/gcc 971MB/s ± 1% 941MB/s ± 0% -3.11% (p=0.008 n=5+5) --- release/c/wuffs-unsupported-snapshot.h | 5 +++-- std/lzw/decode_lzw.wuffs | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.h index c7f885ba..def9233c 100644 --- a/release/c/wuffs-unsupported-snapshot.h +++ b/release/c/wuffs-unsupported-snapshot.h @@ -7176,7 +7176,7 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self, v_n_bits |= 24; } else { while (true) { - while (((uint64_t)(io1_a_src - iop_a_src)) <= 0) { + if (((uint64_t)(io1_a_src - iop_a_src)) <= 0) { if (v_j > 0) { self->private_impl.f_flush_j = v_j; WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); @@ -7185,7 +7185,8 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self, goto suspend; } v_j = 0; - } else { + } + while (((uint64_t)(io1_a_src - iop_a_src)) <= 0) { status = wuffs_base__suspension__short_read; WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); } diff --git a/std/lzw/decode_lzw.wuffs b/std/lzw/decode_lzw.wuffs index 92e7756c..4df33a1d 100644 --- a/std/lzw/decode_lzw.wuffs +++ b/std/lzw/decode_lzw.wuffs @@ -81,15 +81,16 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) { pre n_bits < 12, post n_bits >= width, { - while args.src.available() <= 0, - inv n_bits < 12, - post args.src.available() >= 1, - { + if args.src.available() <= 0 { if j > 0 { this.flush_j = j this.flush!??(dst:args.dst) j = 0 - } else { + } + while args.src.available() <= 0, + inv n_bits < 12, + post args.src.available() > 0, + { yield base."$short read" } }