Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(498)

Issue 166076: code review 166076: Make printing faster by avoiding mallocs and some other... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 7 months ago by r
Modified:
15 years, 7 months ago
Reviewers:
CC:
rsc, golang-dev, hong
Visibility:
Public.

Description

Make printing faster by avoiding mallocs and some other advances. Roughly 33% faster for simple cases, probably more for complex ones. Before: mallocs per Sprintf(""): 4 mallocs per Sprintf("xxx"): 6 mallocs per Sprintf("%x"): 10 mallocs per Sprintf("%x %x"): 12 Now: mallocs per Sprintf(""): 2 mallocs per Sprintf("xxx"): 3 mallocs per Sprintf("%x"): 5 mallocs per Sprintf("%x %x"): 7 Speed improves because of avoiding mallocs and also by sharing a bytes.Buffer between print.go and format.go rather than copying the data back after each printed item. Before: fmt_test.BenchmarkSprintfEmpty 1000000 1346 ns/op fmt_test.BenchmarkSprintfString 500000 3461 ns/op fmt_test.BenchmarkSprintfInt 500000 3671 ns/op Now: fmt_test.BenchmarkSprintfEmpty 2000000 995 ns/op fmt_test.BenchmarkSprintfString 1000000 2745 ns/op fmt_test.BenchmarkSprintfInt 1000000 2391 ns/op fmt_test.BenchmarkSprintfIntInt 500000 3751 ns/op I believe there is more to get but this is a good milestone.

Patch Set 1 #

Patch Set 2 : code review 166076: Make printing faster by avoiding mallocs and some other... #

Total comments: 5

Patch Set 3 : code review 166076: Make printing faster by avoiding mallocs and some other... #

Unified diffs Side-by-side diffs Delta from patch set Stats (+447 lines, -439 lines) Patch
M src/pkg/bytes/buffer.go View 3 chunks +37 lines, -37 lines 0 comments Download
M src/pkg/fmt/fmt_test.go View 1 2 3 chunks +35 lines, -1 line 0 comments Download
M src/pkg/fmt/format.go View 1 2 11 chunks +205 lines, -235 lines 0 comments Download
M src/pkg/fmt/print.go View 1 2 21 chunks +170 lines, -166 lines 0 comments Download

Messages

Total messages: 5
r
Hello rsc (cc: golang-nuts@googlegroups.com), I'd like you to review the following change.
15 years, 7 months ago (2009-12-06 06:30:45 UTC) #1
hong
http://codereview.appspot.com/166076/diff/1001/13 File src/pkg/fmt/format.go (right): http://codereview.appspot.com/166076/diff/1001/13#newcode263 src/pkg/fmt/format.go:263: f.padBytes(f.integer(v, 16, true, ldigits)); Make padBytes() take "clear bool". ...
15 years, 7 months ago (2009-12-06 13:42:13 UTC) #2
rsc
LGTM http://codereview.appspot.com/166076/diff/1001/13 File src/pkg/fmt/format.go (right): http://codereview.appspot.com/166076/diff/1001/13#newcode41 src/pkg/fmt/format.go:41: wid_present bool; dregs widPresent precPresent http://codereview.appspot.com/166076/diff/1001/13#newcode103 src/pkg/fmt/format.go:103: if ...
15 years, 7 months ago (2009-12-06 16:22:03 UTC) #3
r2
there's still lots to do in here, many optimizations, including eliminating string concatenation. this is ...
15 years, 7 months ago (2009-12-06 17:37:45 UTC) #4
r
15 years, 7 months ago (2009-12-06 20:03:58 UTC) #5
*** Submitted as http://code.google.com/p/go/source/detail?r=f967d18ba6d4 ***

Make printing faster by avoiding mallocs and some other advances.
Roughly 33% faster for simple cases, probably more for complex ones.

Before:

mallocs per Sprintf(""): 4
mallocs per Sprintf("xxx"): 6
mallocs per Sprintf("%x"): 10
mallocs per Sprintf("%x %x"): 12

Now:

mallocs per Sprintf(""): 2
mallocs per Sprintf("xxx"): 3
mallocs per Sprintf("%x"): 5
mallocs per Sprintf("%x %x"): 7

Speed improves because of avoiding mallocs and also by sharing a bytes.Buffer
between print.go and format.go rather than copying the data back after each
printed item.

Before:

fmt_test.BenchmarkSprintfEmpty	1000000	      1346 ns/op
fmt_test.BenchmarkSprintfString	500000	      3461 ns/op
fmt_test.BenchmarkSprintfInt	500000	      3671 ns/op

Now:

fmt_test.BenchmarkSprintfEmpty	 2000000	       995 ns/op
fmt_test.BenchmarkSprintfString	 1000000	      2745 ns/op
fmt_test.BenchmarkSprintfInt	 1000000	      2391 ns/op
fmt_test.BenchmarkSprintfIntInt	  500000	      3751 ns/op


I believe there is more to get but this is a good milestone.

R=rsc
CC=golang-dev, hong
http://codereview.appspot.com/166076
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b