Re:Optimizing Go string operations with practical examples
by jensneuse on Sunday December 03, 2023 @02:03AM
(#38505413)
We're using similar techniques to parse and merge JSON objects, which could be applied to this problem as well. Essentially, you could index the whole input into an AST and the. Traverse the AST to find the data you're looking for. In our case, we're not just doing that, but recursively merge JSON objects at the AST level which is a lot faster than merging the actual data. The full blog post on the problem and solution can be found here: https://wundergraph.com/blog/astjson_high_performance_json_t...
[ Parent
| on HN ]
Re:Optimizing Go string operations with practical examples
by kiitos on Sunday December 03, 2023 @06:31AM
(#38506295)
https://github.com/wundergraph/graphql-go-tools/blob/dcd50bd...
Each iteration of this benchmark measures the aggregate performance of
- 1x ParseObject
- 3x AppendObject
- 3x MergeNodesWithPath
- 1x PrintNode
- 1x bytes.Equal comparison of two byte slices
So the benchmark isn't really measuring MergeNodesWithPath, it's measuring a much larger composite operation, which includes (multiple) calls to MergeNodesWithPath but also all of the above listed calls as well.
If you want to measure MergeNodesWithPath, you would need to have each iteration of the loop do a single MergeNodesWithPath call, on the same JSON method receiver, and with the same input parameters.
edit: similar issues exist in many/most of the other benchmark functions as well