Skip to content

Commit

Permalink
inflate: Keep dict on stack (#581)
Browse files Browse the repository at this point in the history
```
λ benchcmp before.txt  after.txt
benchmark                               old ns/op     new ns/op     delta
BenchmarkDecodeDigitsSpeed1e4-32        45478         44642         -1.84%
BenchmarkDecodeDigitsSpeed1e5-32        520045        506007        -2.70%
BenchmarkDecodeDigitsSpeed1e6-32        5213200       5067185       -2.80%
BenchmarkDecodeDigitsDefault1e4-32      49476         48936         -1.09%
BenchmarkDecodeDigitsDefault1e5-32      496733        490872        -1.18%
BenchmarkDecodeDigitsDefault1e6-32      4869294       4851319       -0.37%
BenchmarkDecodeDigitsCompress1e4-32     44262         44419         +0.35%
BenchmarkDecodeDigitsCompress1e5-32     470795        473693        +0.62%
BenchmarkDecodeDigitsCompress1e6-32     4690131       4689175       -0.02%
BenchmarkDecodeTwainSpeed1e4-32         49316         49218         -0.20%
BenchmarkDecodeTwainSpeed1e5-32         531644        527865        -0.71%
BenchmarkDecodeTwainSpeed1e6-32         5316889       5281027       -0.67%
BenchmarkDecodeTwainDefault1e4-32       49570         49543         -0.05%
BenchmarkDecodeTwainDefault1e5-32       492474        488411        -0.83%
BenchmarkDecodeTwainDefault1e6-32       4902696       4844194       -1.19%
BenchmarkDecodeTwainCompress1e4-32      47788         47235         -1.16%
BenchmarkDecodeTwainCompress1e5-32      465616        454616        -2.36%
BenchmarkDecodeTwainCompress1e6-32      4606437       4513280       -2.02%
BenchmarkDecodeRandomSpeed1e4-32        299           296           -0.94%
BenchmarkDecodeRandomSpeed1e5-32        1930          1942          +0.62%
BenchmarkDecodeRandomSpeed1e6-32        19980         19990         +0.05%
```
  • Loading branch information
klauspost committed May 7, 2022
1 parent f28a7e7 commit 20d0f94
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 60 deletions.
20 changes: 10 additions & 10 deletions flate/_gen/gen_inflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (f *decompressor) $FUNCNAME$() {
// Optimization. Compiler isn't smart enough to keep f.b,f.nb in registers,
// but is smart enough to keep local variables in registers, so use nb and b,
// inline call to moreBits and reassign b,nb back to f on return.
fnb, fb := f.nb, f.b
fnb, fb, dict := f.nb, f.b, &f.dict
switch f.stepState {
case stateInit:
Expand Down Expand Up @@ -106,9 +106,9 @@ readLiteral:
var length int
switch {
case v < 256:
f.dict.writeByte(byte(v))
if f.dict.availWrite() == 0 {
f.toRead = f.dict.readFlush()
dict.writeByte(byte(v))
if dict.availWrite() == 0 {
f.toRead = dict.readFlush()
f.step = (*decompressor).$FUNCNAME$
f.stepState = stateInit
f.b, f.nb = fb, fnb
Expand Down Expand Up @@ -251,10 +251,10 @@ readLiteral:
}
// No check on length; encoding can be prescient.
if dist > uint32(f.dict.histSize()) {
if dist > uint32(dict.histSize()) {
f.b, f.nb = fb, fnb
if debugDecode {
fmt.Println("dist > f.dict.histSize():", dist, f.dict.histSize())
fmt.Println("dist > dict.histSize():", dist, dict.histSize())
}
f.err = CorruptInputError(f.roffset)
return
Expand All @@ -267,14 +267,14 @@ readLiteral:
copyHistory:
// Perform a backwards copy according to RFC section 3.2.3.
{
cnt := f.dict.tryWriteCopy(f.copyDist, f.copyLen)
cnt := dict.tryWriteCopy(f.copyDist, f.copyLen)
if cnt == 0 {
cnt = f.dict.writeCopy(f.copyDist, f.copyLen)
cnt = dict.writeCopy(f.copyDist, f.copyLen)
}
f.copyLen -= cnt
if f.dict.availWrite() == 0 || f.copyLen > 0 {
f.toRead = f.dict.readFlush()
if dict.availWrite() == 0 || f.copyLen > 0 {
f.toRead = dict.readFlush()
f.step = (*decompressor).$FUNCNAME$ // We need to continue this work
f.stepState = stateDict
f.b, f.nb = fb, fnb
Expand Down
100 changes: 50 additions & 50 deletions flate/inflate_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 20d0f94

Please sign in to comment.