diff --git a/ast/parser.go b/ast/parser.go index 5dc743953..22fe17bf6 100644 --- a/ast/parser.go +++ b/ast/parser.go @@ -21,6 +21,7 @@ import ( `github.com/bytedance/sonic/internal/native/types` `github.com/bytedance/sonic/internal/rt` + `github.com/bytedance/sonic/option` ) const ( @@ -49,7 +50,7 @@ type Parser struct { dbuf *byte } -var noLazy bool = false +var noLazy = option.AstSafeConcurrentRead /** Parser Private Methods **/ diff --git a/option/option.go b/option/option.go index 71527cdf0..c0a31356d 100644 --- a/option/option.go +++ b/option/option.go @@ -16,6 +16,8 @@ package option +import `os` + var ( // DefaultDecoderBufferSize is the initial buffer size of StreamDecoder DefaultDecoderBufferSize uint = 128 * 1024 @@ -83,4 +85,10 @@ func WithCompileMaxInlineDepth(depth int) CompileOption { o.MaxInlineDepth = depth } } - \ No newline at end of file + +var ( + // AstSafeConcurrentRead indicate that `sonic/ast.Node`` can be concurrently 'Read' + // (for `GetByPath/Get/Index/Int64/String/Bool/Float64/Number/Interface/Map/Array/ForEach/Values/Properties`) + // NOTICE: Use it may cause `ast.Node`` performace decline + AstSafeConcurrentRead = os.Getenv("SONIC_AST_SAFE_CONCURRENT_READ") != "" +) \ No newline at end of file