Skip to content

Commit

Permalink
zstd: Adjust default window sizes (#247)
Browse files Browse the repository at this point in the history
Double window size for default (8MB)
4x for Better (16 MB)
  • Loading branch information
klauspost authored Mar 25, 2020
1 parent badde52 commit 8f4a8f1
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions zstd/encoder_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ type EOption func(*encoderOptions) error

// options retains accumulated state of multiple options.
type encoderOptions struct {
concurrent int
level EncoderLevel
single *bool
pad int
blockSize int
windowSize int
crc bool
fullZero bool
noEntropy bool
concurrent int
level EncoderLevel
single *bool
pad int
blockSize int
windowSize int
crc bool
fullZero bool
noEntropy bool
customWindow bool
}

func (o *encoderOptions) setDefault() {
Expand All @@ -30,7 +31,7 @@ func (o *encoderOptions) setDefault() {
crc: true,
single: nil,
blockSize: 1 << 16,
windowSize: 1 << 22,
windowSize: 8 << 20,
level: SpeedDefault,
}
}
Expand Down Expand Up @@ -85,6 +86,7 @@ func WithWindowSize(n int) EOption {
}

o.windowSize = n
o.customWindow = true
if o.blockSize > o.windowSize {
o.blockSize = o.windowSize
}
Expand Down Expand Up @@ -195,6 +197,16 @@ func WithEncoderLevel(l EncoderLevel) EOption {
return fmt.Errorf("unknown encoder level")
}
o.level = l
if !o.customWindow {
switch o.level {
case SpeedFastest:
o.windowSize = 4 << 20
case SpeedDefault:
o.windowSize = 8 << 20
case SpeedBetterCompression:
o.windowSize = 16 << 20
}
}
return nil
}
}
Expand Down

0 comments on commit 8f4a8f1

Please sign in to comment.