Closed
Description
Going from commit c85b77c (just before the introduction of a printer type to cmd/compile/internal/gc/fmt.go) to 0d23c28 (current tip), I see:
name old time/op new time/op delta
Template 297ms ± 6% 296ms ± 5% ~ (p=1.000 n=14+13)
Unicode 150ms ± 4% 155ms ±10% ~ (p=0.068 n=13+14)
GoTypes 965ms ± 4% 986ms ± 1% +2.16% (p=0.017 n=15+13)
name old alloc/op new alloc/op delta
Template 47.7MB ± 0% 47.2MB ± 0% -1.11% (p=0.000 n=15+15)
Unicode 37.9MB ± 0% 37.9MB ± 0% +0.08% (p=0.000 n=15+13)
GoTypes 143MB ± 0% 145MB ± 0% +1.39% (p=0.000 n=15+15)
name old allocs/op new allocs/op delta
Template 450k ± 0% 463k ± 0% +3.00% (p=0.000 n=15+15)
Unicode 368k ± 0% 374k ± 0% +1.63% (p=0.000 n=15+15)
GoTypes 1.34M ± 0% 1.45M ± 0% +8.58% (p=0.000 n=15+15)
I haven't dug into why, but I suspect that it is because formatting routines that used to simply return a constant string now append that constant string to a byte slice and then convert that byte slice back into a string. If this guess is correct, it could probably be reversed by adding a string field to printer and doing some careful special-casing code in the printer methods.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
griesemer commentedon Aug 27, 2016
@josharian You're probably right but I suggest not jumping to fixing this right now. The fmt.go cleanup is not finished yet, it's just a start. Let's complete the transition and cleanups and then revisit.
josharian commentedon Aug 27, 2016
Sounds good. Just wanted to flag it, since this is a known performance hot spot.
griesemer commentedon Aug 30, 2016
@josharian How did you obtain the results above? I like to re-measure.
josharian commentedon Aug 30, 2016
I now get from that (with master at d6098e4):
The alloc numbers are the ones that I think are probably due to the gc/fmt changes. The CPU numbers may be because I'm running a browser, etc., but I hope they're real! :)
griesemer commentedon Aug 30, 2016
@josharian Thanks. My pending change ( https://go-review.googlesource.com/28072 ) reduces the allocations again somewhat. Following the same script, I now get:
cmd/compile: make internal objects directly print to printer
davecheney commentedon Aug 30, 2016
Just as a data point. I've been keeping my benchmarks up to date and as of
this morning Go tip is slightly slower than 1.7, an average of no more than
2%.
On Wed, 31 Aug 2016, 04:05 Robert Griesemer notifications@github.com
wrote:
griesemer commentedon Aug 30, 2016
@davecheney I wouldn't be surprised if some of it is due to these changes. I'm playing a bit more with it but if I cannot make it net-negative, I'll undo all the fmt changes that didn't explicitly remove code.
davecheney commentedon Aug 30, 2016
@robert I don't think the formatting changes had any effect for or against,
since I started looking a week or so ago go tip has been ~2% slower in my
compile benchmarks than 1.7.
On Wed, Aug 31, 2016 at 9:12 AM, Robert Griesemer notifications@github.com
wrote:
josharian commentedon Aug 30, 2016
If you give up on it, Robert, please let me know before reverting everything.
Dave, if you could identify when the 2% regression started, that'd be useful. But let's leave this bug specifically for the gc/fmt changes.
davecheney commentedon Aug 30, 2016
I'm going to assume it was when the dev.ssa branch was merged in. To be
clear, we're talking about this much
go version go1.7 linux/amd64
real 1m2.428s
user 3m5.858s
sys 0m11.943s
go version devel +b2e0e96 Tue Aug 30 23:10:43 2016 +0000 linux/amd64
real 1m4.310s
user 3m13.133s
sys 0m12.396s
I don't think it's worth alerting the national guard at this early stage of
the game.
On Wed, Aug 31, 2016 at 9:23 AM, Josh Bleecher Snyder <
notifications@github.com> wrote:
griesemer commentedon Aug 30, 2016
@josharian I'm trying to use fmt.Formatter instead of the local printer - that would be nicer and more flexible. So far it looks good.
griesemer commentedon Aug 31, 2016
@josharian I have now implemented fmt.Formatters for all types handled by fmt.go and also converted all source code to use formatted printing. For instance, an
sconv(s, FmtSign)
for the format%v
becomes justs
with the format%+v
(I'm going to make these formats%+S
for better readability).Running the above benchmark above against commit c85b77c and current tip (commit cd0ba4c, excl. my new changes) results in:
This is about what we had yesterday.
Running the above benchmark above against commit c85b77c and and my local tip (incl. my new changes) results in:
This shows an improvement - albeit not as much as I hoped. But the changes should have removed many function calls to the various Xconv routines all over the place. There should also much fewer strings be allocated and concatenated.
For final comparison: Current master tip as above against my local tip:
I'm going to send out a series of CLs (about one dozen in total) with the respective changes.
gopherbot commentedon Sep 12, 2016
CL https://golang.org/cl/29087 mentions this issue.
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels
griesemer commentedon Sep 13, 2016
For the record: With (pending) https://go-review.googlesource.com/29089, we are now at or below the original levels:
(Most of the benefits came from https://go-review.googlesource.com/29087.)
Considering this particular issue fully resolved at this point.
josharian commentedon Sep 13, 2016
Thanks, Robert.
gopherbot commentedon Sep 13, 2016
CL https://golang.org/cl/29089 mentions this issue.
cmd/compile: reduce allocs some more