Skip to content

Commit 1d80d62

Browse files
authored
Update Sonic configuration to further enhance performance (#90)
1 parent ff3786c commit 1d80d62

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

_examples/golang-basics/example.gen.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

imports.go.tmpl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,20 @@ import (
107107

108108
{{- if eq $opts.json "jsoniter" }}
109109

110-
// Opinionated config for -json=jsoniter, see https://github.com/json-iterator/go/blob/master/config.go.
110+
// Opinionated configuration for -json=jsoniter encoding.
111+
// Reference: https://github.com/json-iterator/go/blob/master/config.go
111112
var jsonCfg = jsoniter.Config{
112113
ValidateJsonRawMessage: true,
113114
}.Froze()
114115

115116
{{- else if eq $opts.json "sonic" }}
116117

117-
// Opinionated config for -json=sonic, see https://github.com/bytedance/sonic/blob/main/api.go.
118+
// Opinionated configuration for -json=sonic encoding.
119+
// Reference: https://github.com/bytedance/sonic/blob/main/api.go
118120
var jsonCfg = sonic.Config{
119-
NoNullSliceOrMap: true, // Encode empty Array or Object as '[]' or '{}' instead of 'null'.
120-
CompactMarshaler: true,
121-
CopyString : true,
122-
ValidateString : true,
121+
NoNullSliceOrMap: true, // Encode nil slices/maps as '[]'/'{}' instead of 'null' to prevent runtime issues in JavaScript.
122+
NoValidateJSONMarshaler: true, // Skip validation of JSON output from types implementing json.Marshaler to enhance performance.
123+
NoValidateJSONSkip: true, // Bypass validation when skipping over JSON values during decoding, improving efficiency.
123124
}.Froze()
124125

125126
{{- end -}}

0 commit comments

Comments
 (0)