4 ms·
Some notes from looking at the Go code. I don't know how important are those for performance, more like style nits. Java version doesn't do type conversion: ht
by dchest 14y ago
Some notes from looking at the Go code. I don't know how important are those for performance, more like style nits.
Java version doesn't do type conversion: https://github.com/collinvandyck/go-and-java/blob/master/java/src/main/java/auth/UserDAO.java#L22 https://github.com/collinvandyck/go-and-java/blob/master/jav...
rs.getString("id")
rs.getBoolean("admin")
Go version does conversion at runtime, as row.Scan() accepts interface values.
Also, the usage of sql interface is not optimal (at least with regards to code length) -- since the query is for one row, why not use QueryRow instead of Query?
Authorization header decoding is strange -- it creates new base64 decoder, then string reader, then decodes. Why not just use base64.StdEncoding.DecodeString() and get rid of a few lines of code and a few allocations?
https://github.com/collinvandyck/go-and-java/blob/master/go/auth_resource.go#L57 https://github.com/collinvandyck/go-and-java/blob/master/go/...
Similarly, JSON marshals into a newly allocated slice instead of creating a decoder and then marshaling directly into ResponseWriter.
https://github.com/collinvandyck/go-and-java/blob/master/go/auth_resource.go#L35 https://github.com/collinvandyck/go-and-java/blob/master/go/...
Constants for HTTP error codes, that are declared in net/http, for some reason are redeclared
https://github.com/collinvandyck/go-and-java/blob/master/go/auth_resource.go#L12 https://github.com/collinvandyck/go-and-java/blob/master/go/...
- - -
I sometimes wonder why various benchmarks include colorful charts, but fail to include a few lines from a simple run of profiler. It's so easy to do, and yet nobody bothers to learn where the cycles are actually spent!
- luriel 14y agoAlso somebody in the gonuts list noted that both versions are using the database differently, if you fix the Go version to use prepared statements it doubles throughput.