mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Avoid buffer copies from LZW to GIF
name old speed new speed delta wuffs_lzw_decode_20k/clang 213MB/s ± 0% 224MB/s ± 1% +4.89% (p=0.008 n=5+5) wuffs_lzw_decode_100k/clang 359MB/s ± 1% 393MB/s ± 2% +9.36% (p=0.008 n=5+5) wuffs_lzw_decode_20k/gcc 188MB/s ± 0% 187MB/s ± 0% -0.70% (p=0.008 n=5+5) wuffs_lzw_decode_100k/gcc 223MB/s ± 2% 224MB/s ± 0% ~ (p=0.690 n=5+5) wuffs_gif_decode_1k_bw/clang 227MB/s ± 1% 240MB/s ± 0% +5.89% (p=0.008 n=5+5) wuffs_gif_decode_1k_color/clang 117MB/s ± 0% 125MB/s ± 0% +6.16% (p=0.008 n=5+5) wuffs_gif_decode_10k_bgra/clang 567MB/s ± 1% 599MB/s ± 0% +5.56% (p=0.008 n=5+5) wuffs_gif_decode_10k_indexed/clang 152MB/s ± 0% 159MB/s ± 1% +4.76% (p=0.008 n=5+5) wuffs_gif_decode_100k_artificial/clang 455MB/s ± 1% 504MB/s ± 0% +10.93% (p=0.008 n=5+5) wuffs_gif_decode_100k_realistic/clang 178MB/s ± 2% 194MB/s ± 0% +9.00% (p=0.008 n=5+5) wuffs_gif_decode_1000k/clang 179MB/s ± 1% 197MB/s ± 0% +9.81% (p=0.016 n=5+4) wuffs_gif_decode_anim_screencap/clang 952MB/s ± 0% 1050MB/s ± 1% +10.29% (p=0.008 n=5+5) wuffs_gif_decode_1k_bw/gcc 243MB/s ± 1% 252MB/s ± 0% +3.71% (p=0.008 n=5+5) wuffs_gif_decode_1k_color/gcc 130MB/s ± 0% 133MB/s ± 1% +2.69% (p=0.008 n=5+5) wuffs_gif_decode_10k_bgra/gcc 537MB/s ± 0% 547MB/s ± 1% +1.93% (p=0.008 n=5+5) wuffs_gif_decode_10k_indexed/gcc 163MB/s ± 0% 167MB/s ± 1% +2.40% (p=0.008 n=5+5) wuffs_gif_decode_100k_artificial/gcc 458MB/s ± 0% 471MB/s ± 0% +2.90% (p=0.016 n=5+4) wuffs_gif_decode_100k_realistic/gcc 186MB/s ± 0% 191MB/s ± 0% +3.08% (p=0.008 n=5+5) wuffs_gif_decode_1000k/gcc 189MB/s ± 0% 194MB/s ± 0% +2.70% (p=0.008 n=5+5) wuffs_gif_decode_anim_screencap/gcc 976MB/s ± 0% 1010MB/s ± 0% +3.49% (p=0.008 n=5+5)
This commit is contained in:
1 parent
4164583323
commit
622a76d4c0
4 files changed
+94
-52
No files matched your search
@@ -109,10 +109,7 @@ pub struct decoder?(
|
||||
|
||||
compressed_ri base.u64,
|
||||
compressed_wi base.u64,
|
||||
uncompressed_wi base.u64,
|
||||
|
||||
compressed array[4096] base.u8,
|
||||
uncompressed array[4096] base.u8,
|
||||
|
||||
// palettes[0] and palettes[1] are the Global and Local Color Table.
|
||||
palettes array[2] array[4 * 256] base.u8,
|
||||
@@ -657,23 +654,20 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
||||
while:inner true {
|
||||
var w base.io_writer
|
||||
var r base.io_reader
|
||||
if (this.compressed_ri > this.compressed_wi) or
|
||||
(this.compressed_wi > 4096) or (this.uncompressed_wi > 4096) {
|
||||
if (this.compressed_ri > this.compressed_wi) or (this.compressed_wi > 4096) {
|
||||
return "?internal error: inconsistent ri/wi"
|
||||
}
|
||||
io_bind (io:w, data:this.uncompressed[this.uncompressed_wi:]) {
|
||||
io_bind (io:w, data:this.compressed[:0]) { // TODO: delete.
|
||||
io_bind (io:r, data:this.compressed[this.compressed_ri:this.compressed_wi]) {
|
||||
var z base.status =? this.lzw.decode!??(dst:w, src:r)
|
||||
this.uncompressed_wi ~sat+= w.since_mark().length()
|
||||
this.compressed_ri ~sat+= r.since_mark().length()
|
||||
}
|
||||
}
|
||||
|
||||
if this.uncompressed_wi > 4096 {
|
||||
return "?internal error: inconsistent ri/wi"
|
||||
if this.lzw.available() > 0 {
|
||||
var uncompressed slice base.u8 = this.lzw.take_all!()
|
||||
this.copy_to_image_buffer!?(pb:args.dst, src:uncompressed)
|
||||
}
|
||||
this.copy_to_image_buffer!?(pb:args.dst, src:this.uncompressed[:this.uncompressed_wi])
|
||||
this.uncompressed_wi = 0
|
||||
|
||||
if z.is_ok() {
|
||||
this.previous_lzw_decode_ended_abruptly = false
|
||||
|
||||
@@ -252,12 +252,11 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
|
||||
pri func decoder.flush!??(dst base.io_writer) {
|
||||
var i base.u32[..8191]
|
||||
var j base.u32[..8191] = this.flush_j
|
||||
while true {
|
||||
if i > j {
|
||||
while this.flush_j > 0 {
|
||||
if i > this.flush_j {
|
||||
return "?internal error: inconsistent I/O"
|
||||
}
|
||||
var s slice base.u8 = this.output[i:j]
|
||||
var s slice base.u8 = this.output[i:this.flush_j]
|
||||
var n base.u64 = args.dst.copy_from_slice!(s:s)
|
||||
if n == s.length() {
|
||||
return ok
|
||||
@@ -266,3 +265,17 @@ pri func decoder.flush!??(dst base.io_writer) {
|
||||
yield base."$short write"
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: enforce that available and take_all are only valid to call if decode
|
||||
// was passed a 0-length dst base.io_writer? The (non-obvious) hard part is to
|
||||
// enforce that without regressing benchmarks.
|
||||
|
||||
pub func decoder.available() base.u64 {
|
||||
return this.flush_j as base.u64
|
||||
}
|
||||
|
||||
pub func decoder.take_all!() slice base.u8 {
|
||||
var s slice base.u8 = this.output[:this.flush_j]
|
||||
this.flush_j = 0
|
||||
return s
|
||||
}
|
||||
Reference in new issue
Block a user