4 ms·
I am the author is there a better JSON parser that I should have used for Go?
by Teef 14y ago
I am the author is there a better JSON parser that I should have used for Go?
- fdr 14y agoI don't think so; I think Golang could use a more well-optimized parser implementation, even if it remains written in Go.
- eternalban 14y agoI appreciate why you use "golang" instead of the general "Go" or current release "Go1", but the former is the name of the open source organization, and the latter is the name of the language.
- fdr 14y agoFair. Then what's the name of the implementation? The same as the language? How do I refer to: * Go, the specification * gccgo * 6g and friends: the compilers
- enneff 14y agoGo, gccgo, and gc respectively.
- enneff 14y agoYou are mistaken. There is no organization that maintains the Go project. The project and language are both named Go. "golang" is just the name of the domain and a more searchable term than "go." There is nothing more to it than that.
- supersillyus 14y agoIt certainly could be more optimized. For example, all numeric literals are converted to strings before being parsed. That's a mostly unnecessary copy/allocation per number. Similarly, it doesn't make use of the fact that a []T can only legally contain Ts. It's all very clean and generic, which is great, because when working on the compiler they can work on making good code faster without being mislead by code that tries to work around lack of optimizations. As an experiment, I replaced the []int in the Go code in the link with an IntList that implements json.Unmarshaler, and does a single-pass integer list parsing there (without overflow checking, but eh). With that quick 40 line change, the Go code was faster than the CPython, at least on my machine. That and similar type-specific handling could be built into the json package fairly easily, and would make those cases quite a bit faster. Then again, I bet the Go team would have a better and more general idea.
- mdwrigh2 14y agoI spun the JSON decoding off into a few goroutines and managed to get it down to ~1second (but it was out of order, so didn't quite solve the same problem - though this is fixable). This is was ~10 lines of Go (and only using a single core).
- Teef 14y agoThis was my bad I have updated the post. I should have been marsheling to a more comparable datatype (map[string]interface{}{}) and now the performance is more in line with what I would expect. I need to look into the Unmarshal code to see why this is so slow.
- hartror 14y agoYou could use one of the C json implementations such as json-c. However as has been pointed out you will still be just comparing libraries rather than the languages themselves.