...

Package option

import "github.com/bytedance/sonic/option"
Overview
Index

Overview ▾

Variables

var (
    // DefaultDecoderBufferSize is the initial buffer size of StreamDecoder
    DefaultDecoderBufferSize uint = 128 * 1024

    // DefaultEncoderBufferSize is the initial buffer size of Encoder
    DefaultEncoderBufferSize uint = 128 * 1024
)
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
)

type CompileOption

CompileOption is a function used to change DefaultCompileOptions.

type CompileOption func(o *CompileOptions)

func 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.

func 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 unstability in the first hit.

type CompileOptions

CompileOptions includes all options for encoder or decoder compiler.

type CompileOptions struct {
    // the maximum depth for compilation inline
    MaxInlineDepth int

    // the loop times for recursively pretouch
    RecursiveDepth int
}

func DefaultCompileOptions

func DefaultCompileOptions() CompileOptions

DefaultCompileOptions set default compile options.