proto: fix quadratic behavior in nested map marshaling (#641)
proto: fix quadratic behavior in nested map marshaling (#641)

If the value of a map is a message with nested maps, calling valSizer in marshal may be quadratic -- it will call size at each level. Fix by using cached size if the value type is message.

Benchmark results with @LMMilewski's test case from https://github.com/golang/protobuf/issues/624:

name   old time/op    new time/op    delta
1-12     1.96µs ±19%    1.76µs ±18%     ~     (p=0.075 n=10+10)
2-12     5.10µs ± 6%    3.84µs ± 8%  -24.69%  (p=0.000 n=9+10)
4-12     14.2µs ±12%     8.2µs ±15%  -42.77%  (p=0.000 n=10+10)
8-12     43.0µs ±10%    15.6µs ±11%  -63.81%  (p=0.000 n=9+10)
16-12     138µs ±12%      33µs ±17%  -76.32%  (p=0.000 n=10+10)

name   old alloc/op   new alloc/op   delta
1-12       376B ± 0%      376B ± 0%     ~     (all equal)
2-12       928B ± 0%      752B ± 0%  -18.97%  (p=0.000 n=10+10)
4-12     2.54kB ± 0%    1.49kB ± 0%  -41.51%  (p=0.000 n=10+10)
8-12     7.89kB ± 0%    2.96kB ± 0%  -62.47%  (p=0.000 n=10+10)
16-12    27.0kB ± 0%     5.9kB ± 0%  -78.11%  (p=0.000 n=10+10)

name   old allocs/op  new allocs/op  delta
1-12       12.0 ± 0%      12.0 ± 0%     ~     (all equal)
2-12       28.0 ± 0%      23.0 ± 0%  -17.86%  (p=0.000 n=10+10)
4-12       75.0 ± 0%      45.0 ± 0%  -40.00%  (p=0.000 n=10+10)
8-12        229 ± 0%        89 ± 0%  -61.14%  (p=0.000 n=10+10)
16-12       777 ± 0%       177 ± 0%  -77.22%  (p=0.000 n=10+10)

Fixes #624.
golang/protobuf,fuchsia-mirror/third_party-github.com-golang-protobuf,golang/protobuf,fuchsia-mirror/third_party-github.com-golang-protobuf