Skip to content

Commit

Permalink
add spell check
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Dec 7, 2024
1 parent 6c24c84 commit 63ed2c5
Show file tree
Hide file tree
Showing 38 changed files with 103 additions and 84 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/.ignore_words
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
socio-economic
nd
regArgs
oders
ure
alse
13 changes: 13 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Lint

on: pull_request

jobs:
misc:
runs-on: [self-hosted, X64]
steps:
- uses: actions/checkout@v4
- name: spell check
run: |
pip install codespell==2.3.0
git grep --cached -l '' | xargs codespell --skip 'fuzz/*,*_test.tmpl,testdata/*,*_test.go,go.mod,go.sum,*.gz' --ignore-words=.github/workflows/.ignore_words
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ ret, err := Encode(v, EscapeHTML) // ret == `{"\u0026\u0026":{"X":"\u003c\u003e"

### Compact Format

Sonic encodes primitive objects (struct/map...) as compact-format JSON by default, except marshaling `json.RawMessage` or `json.Marshaler`: sonic ensures validating their output JSON but **DONOT** compacting them for performance concerns. We provide the option `encoder.CompactMarshaler` to add compacting process.
Sonic encodes primitive objects (struct/map...) as compact-format JSON by default, except marshaling `json.RawMessage` or `json.Marshaler`: sonic ensures validating their output JSON but **DO NOT** compacting them for performance concerns. We provide the option `encoder.CompactMarshaler` to add compacting process.

### Print Error

Expand Down Expand Up @@ -480,7 +480,7 @@ But `ast.Visitor` is not a very handy API. You might need to write a lot of code

### Buffer Size

Sonic use memory pool in many places like `encoder.Encode`, `ast.Node.MarshalJSON` to improve performace, which may produce more memory usage (in-use) when server's load is high. See [issue 614](https://github.com/bytedance/sonic/issues/614). Therefore, we introduce some options to let user control the behavior of memory pool. See [option](https://pkg.go.dev/github.com/bytedance/sonic@v1.11.9/option#pkg-variables) package.
Sonic use memory pool in many places like `encoder.Encode`, `ast.Node.MarshalJSON` to improve performance, which may produce more memory usage (in-use) when server's load is high. See [issue 614](https://github.com/bytedance/sonic/issues/614). Therefore, we introduce some options to let user control the behavior of memory pool. See [option](https://pkg.go.dev/github.com/bytedance/sonic@v1.11.9/option#pkg-variables) package.

### Faster JSON skip

Expand Down
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ var (

// API is a binding of specific config.
// This interface is inspired by github.com/json-iterator/go,
// and has same behaviors under equavilent config.
// and has same behaviors under equivalent config.
type API interface {
// MarshalToString returns the JSON encoding string of v
MarshalToString(v interface{}) (string, error)
Expand Down
2 changes: 1 addition & 1 deletion ast/api_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func quote(buf *[]byte, val string) {
quoteString(buf, val)
}

// unquote unescapes a internal JSON string (it doesn't count quotas at the begining and end)
// unquote unescapes an internal JSON string (it doesn't count quotas at the beginning and end)
func unquote(src string) (string, types.ParsingError) {
sp := rt.IndexChar(src, -1)
out, ok := unquoteBytes(rt.BytesFrom(sp, len(src)+2, len(src)+2))
Expand Down
2 changes: 1 addition & 1 deletion ast/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/bytedance/sonic/internal/utils"
)

// Hack: this is used for both checking space and cause firendly compile errors in 32-bit arch.
// Hack: this is used for both checking space and cause friendly compile errors in 32-bit arch.
const _Sonic_Not_Support_32Bit_Arch__Checking_32Bit_Arch_Here = (1 << ' ') | (1 << '\t') | (1 << '\r') | (1 << '\n')

var bytesNull = []byte("null")
Expand Down
2 changes: 1 addition & 1 deletion ast/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ type Scanner func(path Sequence, node *Node) bool
// ForEach scans one V_OBJECT node's children from JSON head to tail,
// and pass the Sequence and Node of corresponding JSON value.
//
// Especailly, if the node is not V_ARRAY or V_OBJECT,
// Especially, if the node is not V_ARRAY or V_OBJECT,
// the node itself will be returned and Sequence.Index == -1.
//
// NOTICE: A unsetted node WON'T trigger sc, but its index still counts into Path.Index
Expand Down
22 changes: 11 additions & 11 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (self *Node) Check() error {

// isRaw returns true if node's underlying value is raw json
//
// Deprecated: not concurent safe
// Deprecated: not concurrent safe
func (self Node) IsRaw() bool {
return self.t & _V_RAW != 0
}
Expand Down Expand Up @@ -440,7 +440,7 @@ func (self *Node) String() (string, error) {
}
}

// StrictString returns string value (unescaped), includeing V_STRING, V_ANY of string.
// StrictString returns string value (unescaped), including V_STRING, V_ANY of string.
// In other cases, it will return empty string.
func (self *Node) StrictString() (string, error) {
if err := self.checkRaw(); err != nil {
Expand Down Expand Up @@ -509,7 +509,7 @@ func (self *Node) Float64() (float64, error) {
}
}

// Float64 exports underlying float64 value, includeing V_NUMBER, V_ANY
// Float64 exports underlying float64 value, including V_NUMBER, V_ANY
func (self *Node) StrictFloat64() (float64, error) {
if err := self.checkRaw(); err != nil {
return 0.0, err
Expand All @@ -527,7 +527,7 @@ func (self *Node) StrictFloat64() (float64, error) {
}
}

/** Sequencial Value Methods **/
/** Sequential Value Methods **/

// Len returns children count of a array|object|string node
// WARN: For partially loaded node, it also works but only counts the parsed children
Expand Down Expand Up @@ -611,7 +611,7 @@ func (self *Node) Unset(key string) (bool, error) {
if err := self.should(types.V_OBJECT); err != nil {
return false, err
}
// NOTICE: must get acurate length before deduct
// NOTICE: must get accurate length before deduct
if err := self.skipAllKey(); err != nil {
return false, err
}
Expand Down Expand Up @@ -657,7 +657,7 @@ func (self *Node) SetAnyByIndex(index int, val interface{}) (bool, error) {
return self.SetByIndex(index, NewAny(val))
}

// UnsetByIndex REOMVE (softly) the node of given index.
// UnsetByIndex REMOVE (softly) the node of given index.
//
// WARN: this will change address of elements, which is a dangerous action.
// Use Unset() for object or Pop() for array instead.
Expand Down Expand Up @@ -957,7 +957,7 @@ func (self *Node) MapUseNumber() (map[string]interface{}, error) {
return self.toGenericObjectUseNumber()
}

// MapUseNode scans both parsed and non-parsed chidren nodes,
// MapUseNode scans both parsed and non-parsed children nodes,
// and map them by their keys
func (self *Node) MapUseNode() (map[string]Node, error) {
if self.isAny() {
Expand Down Expand Up @@ -1102,7 +1102,7 @@ func (self *Node) ArrayUseNumber() ([]interface{}, error) {
return self.toGenericArrayUseNumber()
}

// ArrayUseNode copys both parsed and non-parsed chidren nodes,
// ArrayUseNode copies both parsed and non-parsed children nodes,
// and indexes them by original order
func (self *Node) ArrayUseNode() ([]Node, error) {
if self.isAny() {
Expand Down Expand Up @@ -1147,9 +1147,9 @@ func (self *Node) unsafeArray() (*linkedNodes, error) {
return (*linkedNodes)(self.p), nil
}

// Interface loads all children under all pathes from this node,
// Interface loads all children under all paths from this node,
// and converts itself as generic type.
// WARN: all numberic nodes are casted to float64
// WARN: all numeric nodes are casted to float64
func (self *Node) Interface() (interface{}, error) {
if err := self.checkRaw(); err != nil {
return nil, err
Expand Down Expand Up @@ -1193,7 +1193,7 @@ func (self *Node) packAny() interface{} {
}

// InterfaceUseNumber works same with Interface()
// except numberic nodes are casted to json.Number
// except numeric nodes are casted to json.Number
func (self *Node) InterfaceUseNumber() (interface{}, error) {
if err := self.checkRaw(); err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions decoder/decoder_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,5 @@ func (s SyntaxError) Error() string {
return (*json.SyntaxError)(unsafe.Pointer(&s)).Error()
}

// MismatchTypeError represents dismatching between json and object
type MismatchTypeError json.UnmarshalTypeError
// MismatchTypeError represents mismatching between json and object
type MismatchTypeError json.UnmarshalTypeError
2 changes: 1 addition & 1 deletion decoder/decoder_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Decoder = api.Decoder
// SyntaxError represents json syntax error
type SyntaxError = api.SyntaxError

// MismatchTypeError represents dismatching between json and object
// MismatchTypeError represents mismatching between json and object
type MismatchTypeError = api.MismatchTypeError

// Options for decode.
Expand Down
2 changes: 1 addition & 1 deletion docs/INTRODUCTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Therefore, we decided to **develop a brand-new JSON library with high performanc
Before starting our design, we need to figure out some questions:

### Why is Json-iterator faster than Standard Library?
First of all, the **schema-based processing mechanism** used by the standard library is commendable, in which the parser can obtain meta information in advance when scanning, thereby shortening the time of branch selection. However, its original implementation did not make good use of this mechanism, instead, **it spent a lot of time reflecting to obtain meta info of schema**. Meanwhile, The approach of json-iterator is: Interprete structure as field-by-field encoding and decoding functions, and then assembled and cached them, minimizing the performance loss cost by reflection. But does it work once and for all? No. In practical tests, we found that **the deeper and larger the input JSON got, the smaller the gap between json-iterator and other libraries gradually became** - eventually event got surpassed:
First of all, the **schema-based processing mechanism** used by the standard library is commendable, in which the parser can obtain meta information in advance when scanning, thereby shortening the time of branch selection. However, its original implementation did not make good use of this mechanism, instead, **it spent a lot of time reflecting to obtain meta info of schema**. Meanwhile, The approach of json-iterator is: Interpret structure as field-by-field encoding and decoding functions, and then assembled and cached them, minimizing the performance loss cost by reflection. But does it work once and for all? No. In practical tests, we found that **the deeper and larger the input JSON got, the smaller the gap between json-iterator and other libraries gradually became** - eventually event got surpassed:
![Scalability](./imgs/introduction-1.png)

The reason is that **this implementation transforms into a large number of interface encapsulations and function calls**, followed by function-call losses:
Expand Down
2 changes: 1 addition & 1 deletion internal/decoder/api/decoder_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (


func init() {
// whe in aarch64. we enable all optimize
// when in aarch64, we enable all optimization
envs.EnableOptDec()
envs.EnableFastMap()
}
Expand Down
8 changes: 4 additions & 4 deletions internal/decoder/jitdec/assembler_regabi_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import (
*/

const (
_FP_args = 72 // 72 bytes to pass and spill register arguements
_FP_args = 72 // 72 bytes to pass and spill register arguments
_FP_fargs = 80 // 80 bytes for passing arguments to other Go functions
_FP_saves = 48 // 48 bytes for saving the registers before CALL instructions
_FP_locals = 144 // 144 bytes for local variables
Expand Down Expand Up @@ -203,9 +203,9 @@ var (
var _VAR_fl = jit.Ptr(_SP, _FP_fargs + _FP_saves + 112)

var (
_VAR_et = jit.Ptr(_SP, _FP_fargs + _FP_saves + 120) // save dismatched type
_VAR_et = jit.Ptr(_SP, _FP_fargs + _FP_saves + 120) // save mismatched type
_VAR_pc = jit.Ptr(_SP, _FP_fargs + _FP_saves + 128) // save skip return pc
_VAR_ic = jit.Ptr(_SP, _FP_fargs + _FP_saves + 136) // save dismatched position
_VAR_ic = jit.Ptr(_SP, _FP_fargs + _FP_saves + 136) // save mismatched position
)

type _Assembler struct {
Expand Down Expand Up @@ -1361,7 +1361,7 @@ func (self *_Assembler) _asm_OP_num(_ *_Instr) {
self.Emit("MOVQ", _R9, _VAR_pc)
self.Sjmp("JMP" , _LB_skip_one)

/* assgin string */
/* assign string */
self.Link("_num_next_{n}")
self.slice_from_r(_AX, 0)
self.Emit("BTQ", jit.Imm(_F_copy_string), _ARG_fv)
Expand Down
2 changes: 1 addition & 1 deletion internal/decoder/jitdec/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ func (self *_Compiler) compilePtr(p *_Program, sp int, et reflect.Type) {
self.tab[et] = true

/* not inline the pointer type
* recursing the defined pointer type's elem will casue issue379.
* recursing the defined pointer type's elem will cause issue379.
*/
self.compileOps(p, sp, et)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/decoder/jitdec/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ type _Decoder func(
vp unsafe.Pointer,
sb *_Stack,
fv uint64,
sv string, // DO NOT pass value to this arguement, since it is only used for local _VAR_sv
vk unsafe.Pointer, // DO NOT pass value to this arguement, since it is only used for local _VAR_vk
sv string, // DO NOT pass value to this argument, since it is only used for local _VAR_sv
vk unsafe.Pointer, // DO NOT pass value to this argument, since it is only used for local _VAR_vk
) (int, error)

var _KeepAlive struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/decoder/optdec/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (c *compiler) compilePtr(vt reflect.Type) decFunc {
c.enter(vt)
defer c.exit(vt)

// specail logic for Named Ptr, issue 379
// special logic for Named Ptr, issue 379
if reflect.PtrTo(vt.Elem()) != vt {
c.namedPtr = true
return &ptrDecoder{
Expand Down Expand Up @@ -432,7 +432,7 @@ func (c *compiler) tryCompilePtrUnmarshaler(vt reflect.Type, strOpt bool) decFun

/* check for `encoding.TextMarshaler` with pointer receiver */
if pt.Implements(encodingTextUnmarshalerType) {
/* TextUnmarshal not support ,strig tag */
/* TextUnmarshal not support, string tag */
if strOpt {
panicForInvalidStrType(vt)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/decoder/optdec/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (


func SkipNumberFast(json string, start int) (int, bool) {
// find the number ending, we pasred in native, it alway valid
// find the number ending, we parsed in native, it always valid
pos := start
for pos < len(json) && json[pos] != ']' && json[pos] != '}' && json[pos] != ',' {
if json[pos] >= '0' && json[pos] <= '9' || json[pos] == '.' || json[pos] == '-' || json[pos] == '+' || json[pos] == 'e' || json[pos] == 'E' {
Expand Down Expand Up @@ -40,7 +40,7 @@ func ValidNumberFast(raw string) bool {
return false
}

// check trainling chars
// check trailing chars
for ret < len(raw) {
return false
}
Expand All @@ -49,7 +49,7 @@ func ValidNumberFast(raw string) bool {
}

func SkipOneFast2(json string, pos *int) (int, error) {
// find the number ending, we pasred in sonic-cpp, it alway valid
// find the number ending, we parsed in sonic-cpp, it always valid
start := native.SkipOneFast(&json, pos)
if start < 0 {
return -1, error_syntax(*pos, json, types.ParsingError(-start).Error())
Expand All @@ -58,7 +58,7 @@ func SkipOneFast2(json string, pos *int) (int, error) {
}

func SkipOneFast(json string, pos int) (string, error) {
// find the number ending, we pasred in sonic-cpp, it alway valid
// find the number ending, we parsed in sonic-cpp, it always valid
start := native.SkipOneFast(&json, &pos)
if start < 0 {
// TODO: details error code
Expand Down
6 changes: 3 additions & 3 deletions internal/decoder/optdec/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ type node struct {
val uint64
}

// should consitent with native/parser.c
// should consistent with native/parser.c
type _nospaceBlock struct {
_ [8]byte
_ [8]byte
}

// should consitent with native/parser.c
// should consistent with native/parser.c
type nodeBuf struct {
ncur uintptr
parent int64
Expand All @@ -84,7 +84,7 @@ func (self *nodeBuf) init(nodes []node) {
self.parent = -1
}

// should consitent with native/parser.c
// should consistent with native/parser.c
type Parser struct {
Json string
padded []byte
Expand Down
4 changes: 2 additions & 2 deletions internal/decoder/optdec/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (val Node) ParseF64(ctx *Context) (float64, bool) {
}

func (val Node) ParseString(ctx *Context) (string, bool) {
// shoud not use AsStrRef
// should not use AsStrRef
s, ok := val.AsStr(ctx)
if !ok {
return "", false
Expand All @@ -391,7 +391,7 @@ func (val Node) ParseString(ctx *Context) (string, bool) {


func (val Node) ParseNumber(ctx *Context) (json.Number, bool) {
// shoud not use AsStrRef
// should not use AsStrRef
s, ok := val.AsStr(ctx)
if !ok {
return json.Number(""), false
Expand Down
2 changes: 1 addition & 1 deletion internal/encoder/alg/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func radixQsort(kvs []_MapPair, d, maxDepth int) {
}

// kvs[0:lt] < v = kvs[lt:gt] < kvs[gt:len(kvs)]
// Native implemention:
// Native implementation:
// radixQsort(kvs[:lt], d, maxDepth)
// if p > -1 {
// radixQsort(kvs[lt:gt], d+1, maxDepth)
Expand Down
2 changes: 1 addition & 1 deletion internal/encoder/x86/assembler_regabi_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ func (self *Assembler) encode_string(doubleQuote bool) {
self.Sjmp("JMP", _LB_panic)
self.Link("_str_next_{n}")

/* openning quote, check for double quote */
/* opening quote, check for double quote */
if !doubleQuote {
self.check_size_r(_AX, 2) // SIZE $2
self.add_char('"') // CHAR $'"'
Expand Down
6 changes: 3 additions & 3 deletions internal/optcaching/fcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewSmallFieldMap (hint int) *SmallFieldMap {

func (self *SmallFieldMap) Set(fields []resolver.FieldMeta) {
if len(fields) > 8 {
panic("small field map shoud use in small struct")
panic("small field map should use in small struct")
}

for i, f := range fields {
Expand Down Expand Up @@ -254,7 +254,7 @@ type keysInfo struct {

func (self *NormalFieldMap) Set(fields []resolver.FieldMeta) {
if len(fields) <=8 || len(fields) > 128 {
panic("normal field map shoud use in small struct")
panic("normal field map should use in small struct")
}

// allocate the flat map in []byte
Expand All @@ -278,7 +278,7 @@ func (self *NormalFieldMap) Set(fields []resolver.FieldMeta) {

}

// add a padding size at last to make it firendly for SIMD.
// add a padding size at last to make it friendly for SIMD.
self.keys = make([]byte, _HdrSize + 2 * kvLen, _HdrSize + 2 * kvLen + _PaddingSize)
self.lowOffset = _HdrSize + kvLen

Expand Down
Loading

0 comments on commit 63ed2c5

Please sign in to comment.