-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ast.Visitor for fully decoding JSON into custom generic data containers without using ast.Node #471
Conversation
…a containers without using ast.Node
I will perfect the README after CR :) |
Thanks, we will review it later |
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## main #471 +/- ##
=======================================
Coverage ? 77.92%
=======================================
Files ? 63
Lines ? 10565
Branches ? 0
=======================================
Hits ? 8233
Misses ? 1971
Partials ? 361 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
12cd4ae
to
4f6830b
Compare
07fa6de
to
3d7b182
Compare
72bea6d
to
09c236b
Compare
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/bytedance/sonic](https://togithub.com/bytedance/sonic) | indirect | patch | `v1.10.0-rc` -> `v1.10.1` | --- ### Release Notes <details> <summary>bytedance/sonic (github.com/bytedance/sonic)</summary> ### [`v1.10.1`](https://togithub.com/bytedance/sonic/releases/tag/v1.10.1) [Compare Source](https://togithub.com/bytedance/sonic/compare/v1.10.0...v1.10.1) #### Feature - \[[#​511](https://togithub.com/bytedance/sonic/issues/511)] (ast) support sort keys on non-object node - \[[#​527](https://togithub.com/bytedance/sonic/issues/527)] (encoder) Add `NoValidateJSONMarshaler` option #### Bugfix - \[[#​504](https://togithub.com/bytedance/sonic/issues/504)] (ast) check error before `Set/Unset/Add()` - \[[#​520](https://togithub.com/bytedance/sonic/issues/520)] (native) over boundary bugs of skip number and tolower in native c #### New Contributors - [@​jimyag](https://togithub.com/jimyag) made their first contribution in [bytedance/sonic#501 - [@​hitzhangjie](https://togithub.com/hitzhangjie) made their first contribution in [bytedance/sonic#505 - [@​xiezheng-XD](https://togithub.com/xiezheng-XD) made their first contribution in [bytedance/sonic#516 - [@​andeya](https://togithub.com/andeya) made their first contribution in [bytedance/sonic#527 **Full Changelog**: bytedance/sonic@v1.10.0...v1.10.1 ### [`v1.10.0`](https://togithub.com/bytedance/sonic/releases/tag/v1.10.0) [Compare Source](https://togithub.com/bytedance/sonic/compare/v1.10.0-rc3...v1.10.0) #### Feature - \[[#​493](https://togithub.com/bytedance/sonic/issues/493)] **support Go1.21.0** - \[[#​471](https://togithub.com/bytedance/sonic/issues/471)] (ast) add `ast.Visitor` for transversing JSON in-place - \[[#​470](https://togithub.com/bytedance/sonic/issues/470)] add `Valid()` API #### Bugfix - \[[#​486](https://togithub.com/bytedance/sonic/issues/486)] possible overflowed instruction while handling `byte` type - \[[#​484](https://togithub.com/bytedance/sonic/issues/484)] (decoder) avoid scratched memory of returned error - \[[#​496](https://togithub.com/bytedance/sonic/issues/496)] (ast) Exist() didn't check Valid() first - \[[#​498](https://togithub.com/bytedance/sonic/issues/498)] (ast) drop ast.Node API `UnsafeArray()` and `UnsafeMap()` (**Break Change**) #### Optimization - \[[#​393](https://togithub.com/bytedance/sonic/issues/393)] **refactor `asm2asm` to avoid `SIGPROF` crashing, and enable traceback when C function panics** - \[[#​464](https://togithub.com/bytedance/sonic/issues/464)] (ast) use linked chunk as fundamental storage for nodes to keep node pointer valid (**Break Change**) - \[[#​464](https://togithub.com/bytedance/sonic/issues/464)] (ast) avoid malloc when meeting empty values, and inline header chunk into lazy-parsing stack to reduce malloc. **The performance of `Parse()\Load()\Interface()` promoted 10~60%** - \[[#​475](https://togithub.com/bytedance/sonic/issues/475)] (last) pass `skipnumber` flag to avoid decoding numbers #### New Contributors - [@​xumingyukou](https://togithub.com/xumingyukou) made their first contribution in [bytedance/sonic#447 - [@​zhongxinghong](https://togithub.com/zhongxinghong) made their first contribution in [bytedance/sonic#471 **Full Changelog**: bytedance/sonic@v1.9.2...v1.10.0 ### [`v1.10.0-rc3`](https://togithub.com/bytedance/sonic/compare/v1.10.0-rc2...v1.10.0-rc3) [Compare Source](https://togithub.com/bytedance/sonic/compare/v1.10.0-rc2...v1.10.0-rc3) ### [`v1.10.0-rc2`](https://togithub.com/bytedance/sonic/releases/tag/v1.10.0-rc2) [Compare Source](https://togithub.com/bytedance/sonic/compare/v1.10.0-rc...v1.10.0-rc2) #### Optimization - \[[#​475](https://togithub.com/bytedance/sonic/issues/475)] (ast) pass `skipnumber` flag to avoid decoding numbers - \[[#​483](https://togithub.com/bytedance/sonic/issues/483)] update base64x to finish asm2asm refactor #### Feature - \[[#​471](https://togithub.com/bytedance/sonic/issues/471)] (ast) add `ast.Visitor` for iterating JSON into custom generic data containers in-place #### New Contributors - [@​zhongxinghong](https://togithub.com/zhongxinghong) made their first contribution in [bytedance/sonic#471 **Full Changelog**: bytedance/sonic@v1.10.0-rc...v1.10.0-rc2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on the first day of the month" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDkuNCIsInVwZGF0ZWRJblZlciI6IjM2LjEwOS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
Background
In our business, we want to decode the whole JSON into our custom containers which are neither golang's struct nor map[string]interface{}. They are look like these and can't be replaced by other types:
There are two ways to meet our needs if we use sonic:
We've also designed a custom JSON library to directly decode JSON into our UserNode types without any IR (intermediate representation: interface{} / reflect.Value / ...). It's based on encoding/json with some jsoniter-go's optimization but it's even faster than the second way above. (see benchmark in appendix)
Sonic/ast.Node is designed for processing partial JSON and its APIs are similar to gjson/sjson. It's faster than using map[string]interface{} as IR for decoding generic data. But it is also a kind of IR after all and have lazy-load design, which are useless in our case but causes performance loss. So we want to introduce a Node-free decoder to speed up this case.
Changes
ast/visitor_test.go
to preform the unit-test / benchmark.Discussions
Appendix
Go Version
Benchmark ast.Node vs ast.Visitor
Benchmark in our business (use our dataset)
NOTE: