-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement json.Marshal just for strings (#4979)
We are using json.Marshal() in our code to convert strings to bytes. This function is very generic function and can be used to marshal any type. For our use case, most of the time, this is called for string type. When we dig deeper into the function's code, most of the time is spent on finding the right encoder function for type. In our case stringEncoder. This PR takes away the code of encodeState.string() and defines internally, which is just called for string type. Here are the benchmarks: go test -v -run ^$ -bench BenchmarkJsonMarshal -benchtime=20s [Decoder]: Using assembly version of decoder goos: linux goarch: amd64 pkg: github.com/dgraph-io/dgraph/query BenchmarkJsonMarshal/STDJsonMarshal-largestring-16 11113017 2128 ns/op BenchmarkJsonMarshal/stringJsonMarshal-largestring-16 12233304 1957 ns/op BenchmarkJsonMarshal/STDJsonMarshal-smallstring-16 100000000 252 ns/op BenchmarkJsonMarshal/stringJsonMarshal-smallstring-16 271762213 87.7 ns/op BenchmarkJsonMarshal/STDJsonMarshal-specialchars-16 37255737 636 ns/op BenchmarkJsonMarshal/stringJsonMarshal-specialchars-16 52765609 463 ns/op PASS ok github.com/dgraph-io/dgraph/query 159.218s
- Loading branch information
1 parent
9d3dc3c
commit 827035f
Showing
3 changed files
with
368 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.