Skip to content

Commit d39907e

Browse files
committed
doc/go1.4.html: runtime and performance
LGTM=adg, rsc R=golang-codereviews, adg, bradfitz, dave, rsc CC=golang-codereviews https://golang.org/cl/164090044
1 parent 138b5cc commit d39907e

File tree

1 file changed

+77
-4
lines changed

1 file changed

+77
-4
lines changed

doc/go1.4.html

+77-4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,59 @@ <h3 id="foobarblatz">FooBarBlatz</h3>
8787
TODO news about foobarblatz
8888
</p>
8989

90+
<h2 id="runtime">Changes to the runtime</h2>
91+
92+
<p>
93+
Up to Go 1.4, the runtime (garbage collector, concurrency support, interface management,
94+
maps, slices, strings, ...) was mostly written in C, with some assembler support.
95+
In 1.4, much of the code has been translated to Go so that the garbage collector can scan
96+
the stacks of programs in the runtime and get accurate information about what variables
97+
are active.
98+
This change was large but should have no semantic effect on programs.
99+
</p>
100+
101+
<p>
102+
This rewrite allows the garbage collector in 1.4 to be fully precise,
103+
meaning that it is aware of the location of all active pointers in the program.
104+
This means the heap will be smaller as there will be no false positives keeping non-pointers alive.
105+
Other related changes also reduce the heap size, which is smaller by 10%-30% overall
106+
relative to the previous release.
107+
</p>
108+
109+
<p>
110+
A consequence is that stacks are no longer segmented, eliminating the "hot split" problem.
111+
When a stack limit is reached, a new, larger stack is allocated, all active frames for
112+
the goroutine are copied there, and any pointers into the stack are updated.
113+
Performance can be noticeably better in some cases and is always more predictable.
114+
Details are available in <a href="/s/contigstacks">the design document</a>.
115+
</p>
116+
117+
<p>
118+
The use of contiguous stacks means that stacks can start smaller without triggering performance issues,
119+
so the default starting size for a goroutine's stack in 1.4 has been reduced to 2048 bytes from 8192 bytes.
120+
TODO: It may be bumped to 4096 for the release.
121+
</p>
122+
123+
<p>
124+
As preparation for the concurrent garbage collector scheduled for the 1.5 release,
125+
writes to pointer values in the heap are now done by a function call,
126+
called a write barrier, rather than directly from the function updating the value.
127+
In this next release, this will permit the garbage collector to mediate writes to the heap while it is running.
128+
This change has no semantic effect on programs in 1.4, but was
129+
included in the release to test the compiler and the resulting performance.
130+
</p>
131+
132+
<p>
133+
The implementation of interface values has been modified.
134+
In earlier releases, the interface contained a word that was either a pointer or a one-word
135+
scalar value, depending on the type of the concrete object stored.
136+
This implementation was problematical for the garbage collector,
137+
so as of 1.4 interface values always hold a pointer.
138+
In running programs, most interface values were pointers anyway,
139+
so the effect is minimal, but programs that store integers (for example) in
140+
interfaces will see more allocations.
141+
</p>
142+
90143
<h2 id="compatibility">Changes to the compatibility guidelines</h2>
91144

92145
<p>
@@ -177,7 +230,29 @@ <h3 id="misc">Miscellany</h3>
177230
<h2 id="performance">Performance</h2>
178231

179232
<p>
180-
TODO performance news
233+
Most programs will run about the same speed or slightly faster in 1.4 than in 1.3;
234+
some will be slightly slower.
235+
There are many changes, making it hard to be precise about what to expect.
236+
</p>
237+
238+
<p>
239+
As mentioned above, much of the runtime was translated to Go from C,
240+
which led to some reduction in heap sizes.
241+
It also improved performance slightly because the Go compiler is better
242+
at optimization, due to things like inlining, than the C compiler used to build
243+
the runtime.
244+
</p>
245+
246+
<p>
247+
The garbage collector was sped up, leading to measurable improvements for
248+
garbage-heavy programs.
249+
On the other hand, the new write barriers slow things down again, typically
250+
by about the same amount but, depending on their behavior, some programs
251+
may be somewhat slower or faster.
252+
</p>
253+
254+
<p>
255+
Library changes that affect performance are documented below.
181256
</p>
182257

183258
<h2 id="library">Changes to the standard library</h2>
@@ -209,8 +284,6 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
209284

210285
<pre>
211286

212-
the directory src/pkg has been deleted, for instance src/pkg/fmt is now just src/fmt (CL 134570043)
213-
214287
cmd/6l, liblink: use pc-relative addressing for all memory references, so that linking Go binaries at high addresses works (CL 125140043). This cuts the maximum size of a Go binary's text+data+bss from 4GB to 2GB.
215288
cmd/go: import comments (CL 124940043)
216289
cmd/go: implement "internal" (CL 120600043)
@@ -237,8 +310,8 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
237310
net/http/httputil: add ReverseProxy.ErrorLog (CL 132750043)
238311
os: implement symlink support for windows (CL 86160044)
239312
reflect: add type.Comparable (CL 144020043)
313+
reflect: Value is one word smaller
240314
runtime: implement monotonic clocks on windows (CL 108700045)
241-
runtime: memory consumption is reduced by 10-30% (CL 106260045 removes type info from heap, CL 145790043 reduces stack size to 2K (4K on plan 9 and windows))
242315
runtime: MemStats.Mallocs now counts very small allocations missed in Go 1.3. This may break tests using runtime.ReadMemStats or testing.AllocsPerRun by giving a more accurate answer than Go 1.3 did (CL 143150043).
243316
runtime/race: freebsd is supported (CL 107270043)
244317
swig: Due to runtime changes Go 1.4 will require SWIG 3.0.3 (not yet released)

0 commit comments

Comments
 (0)