Go commit 流し読み(2017/3/12)
Goでその日Mergeされたもののうち、ある程度大きいものを取り上げていきます。 tenntennさんの影響でGoにcontributeして以降せっかく毎日commitを追っているから、ということでy_yagiさんをリスペクトして始めましたが、毎日続けるのはつらそうなので気の向いたときに記事にしようと思います。(要望があればがんばるかもしれません)
cmd/vet: eliminate “might be too small for shift” warnings
Issueに対する修正です。
func f(i int) int { return i >> 32 }
以前までは上記のコードにあるようなマシン依存型である int
, uint
, uintptr
に対して、vetが might be too small for shift
という警告を出してしまっていました。
この変更によって、GOARCH
環境変数が設定されている場合はそこから int
,uint
,uintptr
のビットサイズを決定し、それ以外の場合にはホスト固有のサイズを使用するようになりました。
strconv: fix performance regression in integer formatting on 32bit platforms
32ビットプラットフォームでの整数フォーマットのパフォーマンス改善をしています。この変更は64bitプラットフォームにはほとんど影響がありません。
strconv: use % instead of computing the remainder from the quotientに関連したCLです。
上記のCLでは、1つのDIV命令の場合にコンパイラが /
と %
を順番に認識すると想定していました。
しかし、別々のランタイムの関数を使用して除算とモジュロを計算している32bitプラットフォーム上の64bitオペランドでは順番に認識されるとは限りません。
そのため、上記のCLで消されてしまった32bitプラットフォームで有益な最適化を復元しています。
ベンチマークは以下の通りです。
386
name | old time/op | new time/op | delta |
---|---|---|---|
FormatInt-2 | 6.06µs ± 0% | 6.02µs ± 0% | -0.70% | (p=0.000 n=20+20) |
AppendInt-2 | 4.98µs ± 0% | 4.98µs ± 0% | ~ |(p=0.747 n=18+18) |
FormatUint-2 | 1.93µs ± 0% | 1.85µs ± 0% | -4.19%| (p=0.000 n=20+20) |
AppendUint-2 | 1.71µs ± 0% | 1.64µs ± 0% | -3.68%| (p=0.000 n=20+20) |
amd64
name | old time/op | new time/op | delta |
---|---|---|---|
FormatInt-2 | 2.41µs ± 0% | 2.41µs ± 0% | -0.09% | (p=0.010 n=18+18) |
AppendInt-2 | 1.77µs ± 0% | 1.77µs ± 0% | +0.08% | (p=0.000 n=18+18) |
FormatUint-2 | 653ns ± 1% | 653ns ± 0% | ~ |(p=0.178 n=20+20) |
AppendUint-2 | 514ns ± 0% | 513ns ± 0% | -0.13% | (p=0.000 n=20+17) |