From 8ab2a33aae0b7fe42cbafe29abf61d437ef77b3a Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 24 Nov 2018 10:17:16 +1100 Subject: [PATCH] Update GIF frame_dirty_rect more frequently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's not an optimization per se, but for the record: name old speed new speed delta wuffs_gif_decode_1k_bw/clang 260MB/s ± 1% 261MB/s ± 0% +0.51% (p=0.032 n=5+5) wuffs_gif_decode_1k_color/clang 122MB/s ± 0% 123MB/s ± 1% ~ (p=0.222 n=5+5) wuffs_gif_decode_10k/clang 148MB/s ± 1% 148MB/s ± 0% ~ (p=0.421 n=5+5) wuffs_gif_decode_100k_artificial/clang 439MB/s ± 0% 443MB/s ± 1% +0.99% (p=0.008 n=5+5) wuffs_gif_decode_100k_realistic/clang 174MB/s ± 1% 173MB/s ± 1% ~ (p=0.151 n=5+5) wuffs_gif_decode_1000k/clang 175MB/s ± 0% 175MB/s ± 0% -0.30% (p=0.016 n=4+5) wuffs_gif_decode_anim_screencap/clang 941MB/s ± 1% 948MB/s ± 0% +0.74% (p=0.016 n=5+5) wuffs_gif_decode_1k_bw/gcc 266MB/s ± 0% 273MB/s ± 0% +2.60% (p=0.008 n=5+5) wuffs_gif_decode_1k_color/gcc 137MB/s ± 0% 139MB/s ± 0% +1.54% (p=0.008 n=5+5) wuffs_gif_decode_10k/gcc 163MB/s ± 0% 162MB/s ± 0% ~ (p=0.151 n=5+5) wuffs_gif_decode_100k_artificial/gcc 457MB/s ± 0% 456MB/s ± 0% ~ (p=0.095 n=5+5) wuffs_gif_decode_100k_realistic/gcc 184MB/s ± 0% 182MB/s ± 0% -1.02% (p=0.008 n=5+5) wuffs_gif_decode_1000k/gcc 186MB/s ± 0% 184MB/s ± 0% -1.04% (p=0.016 n=5+4) wuffs_gif_decode_anim_screencap/gcc 985MB/s ± 1% 980MB/s ± 0% ~ (p=0.095 n=5+5) --- release/c/wuffs-unsupported-snapshot.h | 44 ++++++++++++++++---------- std/gif/decode_gif.wuffs | 22 +++++++++---- test/c/std/gif.c | 8 ++--- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.h index ce59de62..e0d0b6e6 100644 --- a/release/c/wuffs-unsupported-snapshot.h +++ b/release/c/wuffs-unsupported-snapshot.h @@ -9137,8 +9137,18 @@ wuffs_gif__decoder__decode_id_part1(wuffs_gif__decoder* self, ((uint32_t)(v_lw))); self->private_impl.f_previous_lzw_decode_ended_abruptly = true; while (true) { + if (((uint64_t)(io1_a_src - iop_a_src)) == 0) { + if (self->private_impl.f_uncompressed_ri != + self->private_impl.f_uncompressed_wi) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + status = wuffs_gif__decoder__copy_to_image_buffer(self, a_dst); + if (status) { + goto suspend; + } + } + } { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) { status = wuffs_base__suspension__short_read; goto suspend; @@ -9199,32 +9209,34 @@ wuffs_gif__decoder__decode_id_part1(wuffs_gif__decoder* self, io1_v_w = o_0_io1_v_w; a_src = o_0_a_src; } - if (wuffs_base__status__is_ok(v_z) || - (v_z == wuffs_base__suspension__short_write)) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - status = wuffs_gif__decoder__copy_to_image_buffer(self, a_dst); - if (status) { - goto suspend; - } - if (v_z == wuffs_base__suspension__short_write) { - goto label_1_continue; - } - self->private_impl.f_previous_lzw_decode_ended_abruptly = false; - goto label_1_break; - } if ((v_block_size == 0) && (v_z == wuffs_base__suspension__short_read)) { goto label_1_break; } + if (self->private_impl.f_uncompressed_ri != + self->private_impl.f_uncompressed_wi) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + status = wuffs_gif__decoder__copy_to_image_buffer(self, a_dst); + if (status) { + goto suspend; + } + } + if (wuffs_base__status__is_ok(v_z)) { + self->private_impl.f_previous_lzw_decode_ended_abruptly = false; + goto label_1_break; + } + if (v_z == wuffs_base__suspension__short_write) { + goto label_1_continue; + } status = v_z; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8); } label_1_break:; } label_0_break:; if (self->private_impl.f_uncompressed_ri != self->private_impl.f_uncompressed_wi) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); status = wuffs_gif__decoder__copy_to_image_buffer(self, a_dst); if (status) { goto suspend; diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index 8e667830..5f72a207 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -606,6 +606,11 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade this.previous_lzw_decode_ended_abruptly = true while true { + if args.src.available() == 0 { + if this.uncompressed_ri != this.uncompressed_wi { + this.copy_to_image_buffer!??(pb:args.dst) + } + } var block_size base.u64 = args.src.read_u8!??() as base.u64 if block_size == 0 { break @@ -629,18 +634,21 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade block_size ~sat-= args.src.since_mark().length() } - if z.is_ok() or (z == status "$short write") { - this.copy_to_image_buffer!??(pb:args.dst) + if (block_size == 0) and (z == status "$short read") { + break:inner + } - if z == status "$short write" { - continue:inner - } + if this.uncompressed_ri != this.uncompressed_wi { + this.copy_to_image_buffer!??(pb:args.dst) + } + + if z.is_ok() { // TODO: check that block_size is zero? this.previous_lzw_decode_ended_abruptly = false break:inner } - if (block_size == 0) and (z == status "$short read") { - break:inner + if z == status "$short write" { + continue:inner } yield z } diff --git a/test/c/std/gif.c b/test/c/std/gif.c index 7e6ee122..a543cd56 100644 --- a/test/c/std/gif.c +++ b/test/c/std/gif.c @@ -862,9 +862,7 @@ const char* test_wuffs_gif_frame_dirty_rect() { // 2, 6, 10, ..., 22, 26, 1, 3, 5, ..., 25, 27. As we progress, the dirty // rect's max_excl_y should be one more than the highest decoded row so far. // If we haven't decoded any rows yet, max_excl_y should be zero. - // - // TODO: this should be 0, 1, 9, 17, 25, 27, 28. - uint32_t wants[2] = {0, 28}; + uint32_t wants[7] = {0, 1, 9, 17, 25, 27, 28}; int i = 0; while (true) { @@ -1135,7 +1133,7 @@ const char* test_wuffs_gif_io_position_two_chunks() { return do_test_wuffs_gif_io_position(true); } - // ---------------- Mimic Tests +// ---------------- Mimic Tests #ifdef WUFFS_MIMIC @@ -1319,7 +1317,7 @@ const char* bench_wuffs_gif_decode_anim_screencap() { "test/data/gifplayer-muybridge.gif", 1); } - // ---------------- Mimic Benches +// ---------------- Mimic Benches #ifdef WUFFS_MIMIC