option
v1.15.5
Documentation
pkg.go.dev ↗Variables
DefaultDecoderBufferSize (4 declarations)
var ( // DefaultDecoderBufferSize is the initial buffer size of StreamDecoder DefaultDecoderBufferSize uint = 4 * 1024 // DefaultEncoderBufferSize is the initial buffer size of Encoder DefaultEncoderBufferSize uint = 4 * 1024 // DefaultAstBufferSize is the initial buffer size of ast.Node.MarshalJSON() DefaultAstBufferSize uint = 4 * 1024 // LimitBufferSize indicates the max pool buffer size, in case of OOM. // See issue https://github.com/bytedance/sonic/issues/614 LimitBufferSize uint = 1024 * 1024 )
DefaultMaxInlineDepth (2 declarations)
var ( // Default value(3) means the compiler only inline 3 layers of nested struct. // when the depth exceeds, the compiler will recurse // and compile subsequent structs when they are decoded DefaultMaxInlineDepth = 3 // Default value(1) means `Pretouch()` will be recursively executed once, // if any nested struct is left (depth exceeds MaxInlineDepth) DefaultRecursiveDepth = 1 )
Types
CompileOption
type CompileOption func(o *CompileOptions)
CompileOption is a function used to change DefaultCompileOptions.
WithCompileEncOnlyOmitNull
func WithCompileEncOnlyOmitNull(omit bool) CompileOption
WithCompileEncOnlyOmitNull sets the encoder to only omit nil value instead of zero value with `omitempty` tag.
WithCompileMaxInlineDepth
func WithCompileMaxInlineDepth(depth int) CompileOption
WithCompileMaxInlineDepth sets the max depth of inline compile in decoder and encoder.
For large nested struct, try to set smaller depth to reduce compiling time.
WithCompileRecursiveDepth
func WithCompileRecursiveDepth(loop int) CompileOption
WithCompileRecursiveDepth sets the loop times of recursive pretouch in both decoder and encoder, for both concrete type and its pointer type.
For deep nested struct (depth exceeds MaxInlineDepth), try to set more loops to completely compile, thus reduce JIT instability in the first hit.
CompileOptions
type CompileOptions struct {
// the maximum depth for compilation inline
MaxInlineDepth int
// the loop times for recursively pretouch
RecursiveDepth int
// EncOnlyOmitNull sets the encoder to only omit nil value (ex: nil pointer, nil container) instead of zero value,
// with `omitempty` tag.
EncOnlyOmitNull bool
}
CompileOptions includes all options for encoder or decoder compiler.
DefaultCompileOptions
func DefaultCompileOptions() CompileOptions
DefaultCompileOptions set default compile options.