Skip to content

Commit 22de983

Browse files
authored
zstd: Add bigger default blocks (#469)
Keep 64K blocks for fastest, but do max size for others. Healthy compression increase for streams.
1 parent 8eae845 commit 22de983

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

zstd/encoder_options.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type encoderOptions struct {
2424
allLitEntropy bool
2525
customWindow bool
2626
customALEntropy bool
27+
customBlockSize bool
2728
lowMem bool
2829
dict *dict
2930
}
@@ -33,7 +34,7 @@ func (o *encoderOptions) setDefault() {
3334
concurrent: runtime.GOMAXPROCS(0),
3435
crc: true,
3536
single: nil,
36-
blockSize: 1 << 16,
37+
blockSize: maxCompressedBlockSize,
3738
windowSize: 8 << 20,
3839
level: SpeedDefault,
3940
allLitEntropy: true,
@@ -106,6 +107,7 @@ func WithWindowSize(n int) EOption {
106107
o.customWindow = true
107108
if o.blockSize > o.windowSize {
108109
o.blockSize = o.windowSize
110+
o.customBlockSize = true
109111
}
110112
return nil
111113
}
@@ -222,6 +224,9 @@ func WithEncoderLevel(l EncoderLevel) EOption {
222224
switch o.level {
223225
case SpeedFastest:
224226
o.windowSize = 4 << 20
227+
if !o.customBlockSize {
228+
o.blockSize = 1 << 16
229+
}
225230
case SpeedDefault:
226231
o.windowSize = 8 << 20
227232
case SpeedBetterCompression:

0 commit comments

Comments
 (0)