Skip to content

Commit b5cd744

Browse files
authored
zstd: Increase speed on incompressible data for best/fastest (#314)
Increase speed of incompressible data for "best" mode. Should not have any impact on compressible data: before/after... ``` sharnd.out.2gb zskp 4 2147483647 2147581961 52931 38.69 sharnd.out.2gb zskp 4 2147483647 2147581961 15426 132.76 silesia.tar zskp 4 211947520 61381950 8394 24.08 silesia.tar zskp 4 211947520 61327981 8142 24.82 BenchmarkRandom10MBEncodeAllFastest-32 279 3971326 ns/op 2640.37 MB/s 0 B/op 0 allocs/op BenchmarkRandom10MBEncodeAllFastest-32 349 3498572 ns/op 2997.15 MB/s 0 B/op 0 allocs/op ```
1 parent 6c96f3e commit b5cd744

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

zstd/enc_best.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (e *bestFastEncoder) Encode(blk *blockEnc, src []byte) {
112112
// Override src
113113
src = e.hist
114114
sLimit := int32(len(src)) - inputMargin
115-
const kSearchStrength = 12
115+
const kSearchStrength = 10
116116

117117
// nextEmit is where in src the next emitLiteral should start from.
118118
nextEmit := s
@@ -186,9 +186,11 @@ encodeLoop:
186186
best = bestOf(best, matchAt(s-offset1+1, s+1, uint32(cv>>8), 1))
187187
best = bestOf(best, matchAt(s-offset2+1, s+1, uint32(cv>>8), 2))
188188
best = bestOf(best, matchAt(s-offset3+1, s+1, uint32(cv>>8), 3))
189-
best = bestOf(best, matchAt(s-offset1+3, s+3, uint32(cv>>24), 1))
190-
best = bestOf(best, matchAt(s-offset2+3, s+3, uint32(cv>>24), 2))
191-
best = bestOf(best, matchAt(s-offset3+3, s+3, uint32(cv>>24), 3))
189+
if best.length > 0 {
190+
best = bestOf(best, matchAt(s-offset1+3, s+3, uint32(cv>>24), 1))
191+
best = bestOf(best, matchAt(s-offset2+3, s+3, uint32(cv>>24), 2))
192+
best = bestOf(best, matchAt(s-offset3+3, s+3, uint32(cv>>24), 3))
193+
}
192194
}
193195
// Load next and check...
194196
e.longTable[nextHashL] = prevEntry{offset: s + e.cur, prev: candidateL.offset}

zstd/enc_fast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (e *fastEncoder) Encode(blk *blockEnc, src []byte) {
7878
// TEMPLATE
7979
const hashLog = tableBits
8080
// seems global, but would be nice to tweak.
81-
const kSearchStrength = 8
81+
const kSearchStrength = 7
8282

8383
// nextEmit is where in src the next emitLiteral should start from.
8484
nextEmit := s

zstd/encoder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ func BenchmarkRandom10MBEncodeAllFastest(b *testing.B) {
10241024
rng := rand.New(rand.NewSource(1))
10251025
data := make([]byte, 10<<20)
10261026
rng.Read(data)
1027-
enc, _ := NewWriter(nil, WithEncoderLevel(SpeedFastest), WithEncoderConcurrency(1))
1027+
enc, _ := NewWriter(nil, WithEncoderLevel(SpeedFastest), WithEncoderConcurrency(2))
10281028
defer enc.Close()
10291029
dst := enc.EncodeAll(data, nil)
10301030
wantSize := len(dst)

0 commit comments

Comments
 (0)