On 2013/08/01 21:43:30, r wrote:
> Because I don't want any more of this in the library. Because I'd
rather
> see the compiler improve. Because packages that use unsafe can't be
> deployed in some environments, which means we need two versions of the
> code, which makes the code harder to maintain and test. Because it's
ugly
> and unreadable.
> Most important, because it's unsafe.
The only environment that I know of which doesn't allow package unsafe
to be used
is App Engine, and that's for user code, not standard library code
(otherwise, the math
package would have a safe version of Float32bits and the other functions
in math/unsafe.go).
Furthermore, I'm sure the majority of Go users don't care about App
Engine (but obviously Google does).
I'd also love the compiler to improve when it comes to []byte to string
conversion, but we have to be pragmatic
in the meantime. The usage of the unsafe package we're discussing
involves *one line*, which
speeds up the code significantly and reduces the number of allocations
by 50%, which in turn
benefits real world code immensely because the pressure on the GC is
reduced. Heck, most people
would call that an epic win.
In an ideal world, the compiler would produce a []byte to string
conversion without copying and/or the
runtime would have no problem dealing with the additional garbage
generated, but it's not the case right
now. By adding one ugly line we can ship a way better JSON decoder which
is gonna help a lot of
Go users. When the compiler and/or runtime improve, that line can be
changed to a simple cast and the
code will be beautiful again, and everyone will be happy.
In the meantime, I take full responsibility for that ugly line of code.
You can punch me in the face once for every
problem it causes down the line. And, yes, you can get that on writing,
signed by me.
Regards,
Alberto
https://codereview.appspot.com/12243043/