feat: introduce ast.Value
to support read and write concurrently
#579
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
sonic/ast.Node
provide completed and efficient APIs to manipulate JSON. However, due to itstransversely-lazy-load
design, it CANNOT be read concurrently, result in limited usage in practice -- or abuse usage ofLoadAll()
.Therefore, we consider introduce a new type
ast.Value
, whose APIs are all based on JSONskipping-and-searching
algorithm, can naturally support concurrently readThread Safty
GetXX()
: All read APIs are implemented bysearching-and-skipping
raw JSON, and returned a slice of the origin -- Thus it is thread-safeSetXX()
: All write APIs are implemented based onGetXX()
, and returned a new copy to the origin -- Thus it is also thread-safe, while the correctness of currently-writing need user to ensure by itselfPerformance
Value
's performance is close toNode
, and 3x~10x times faster than the same API ofgjson
|sjson
!!!