Skip to content

Commit e060b72

Browse files
committed
more edits
1 parent 679aaaf commit e060b72

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

3-compiler-optimisations/1-compiler-optimisations.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ However, a goroutine's stack exists as a cheap place to store local variables; t
2727
In some languages, for example C and C++, the choice of allocating on the stack or on the heap is a manual exercise for the programmer--heap allocations are made with `malloc` and `free`, stack allocation is via `alloca`. Mistakes using these mechanisms are a common cause of memory corruption bugs.
2828

2929
In Go, the compiler automatically moves a value to the heap if if lives beyond the lifetime of the function call. It is said that the value _escapes_ to the heap.
30-
```
30+
```go
3131
type Foo struct {
3232
a, b, c, d int
3333
}
@@ -235,15 +235,9 @@ Adjusting the _inlining level_ is performed with the `-gcflags=-l` flag. Somewha
235235

236236
### Inlining future (Go 1.12)
237237

238-
We're using Go 1.10 for this workshop. A bunch of work happened under the hood for 1.11, but the rules around what is inlined and when have not changed substantively with one exception
239-
240-
A lot of what we've discussed with respect to leaf functions _may_ change in a future release of Go.
241-
242-
There has been work going on in the background since Go 1.8 to enable, so called, mid-stack inlining.
243-
244-
As a Go programmer, this should not be a cause for alarm, mid-
238+
We're using Go 1.10 for this workshop. A bunch of work happened under the hood for 1.11, but the rules around what is inlined and when have not changed substantively with one exception, mid stack inlining.
245239

246-
.link https://github.com/golang/proposal/blob/master/design/19348-midstack-inlining.md Proposal: Mid-stack inlining in the Go compiler
240+
Mid stack inlining is not enabled by default, even in Go 1.11 or tip, but at some point it will be. A lot of what we've discussed with respect to leaf functions _may_ change in a future release of Go.
247241

248242
## Dead code elimination
249243

7-tips-and-tricks/1-tips-and-tricks.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tips and Tricks
22

3-
This final section contains a number of tips to optimise Go code.
3+
This section contains a number of tips to optimise Go code.
44

55
## Reduce allocations
66

@@ -141,6 +141,10 @@ In your design, some goroutines may run until the program exits. These goroutine
141141

142142
**Never start a goroutine without knowing how it will stop**
143143

144+
A good way to achieve this is to use something like [run.Group][4], [workgroup.Group][5], or similar.
145+
146+
Peter Bourgon has a great presentation on the design behing run.Group from GopherCon EU
147+
144148
### Further reading
145149

146150
- [Concurrency Made Easy][0] (video)
@@ -206,13 +210,13 @@ defer func() {
206210
mu.Unlock()
207211
}()
208212
```
209-
`defer` is expensive if the work being done is small, the classic example is `defer` ing a mutex unlock around a struct variable or map lookup. You may choose to avoid `defer` in those situations.
213+
`defer` can be expensive if the work being done is small, the classic example is `defer` ing a mutex unlock around a struct variable or map lookup. You may choose to avoid `defer` in those situations.
210214

211215
This is a case where readability and maintenance is sacrificed for a performance win.
212216

213217
#### Always revisit these decisions.
214218

215-
.link https://github.com/golang/go/issues/9704#issuecomment-251003577
219+
However, in revising this presentation, I have not been able to write a program that demonstrates a measurable cost from using `defer` -- the compiler is getting very good at eliminating the cost of using defer.
216220

217221
## Avoid Finalisers
218222

@@ -260,17 +264,17 @@ Old versions of Go will never get better. They will never get bug fixes or optim
260264
- Go 1.5 and 1.6 had a slower compiler, but it produces faster code, and has a faster GC.
261265
- Go 1.7 delivered roughly a 30% improvement in compilation speed over 1.6, a 2x improvement in linking speed (better than any previous version of Go).
262266
- Go 1.8 will deliver a smaller improvement in compilation speed (at this point), but a significant improvement in code quality for non Intel architectures.
267+
- Go 1.9, 1.10, 1.11 continue to drive down the GC pause time and improve the quality of generated code.
263268

264269
Old version of Go receive no updates. Do not use them. Use the latest and you will get the best performance.
265270

266-
.link http://dave.cheney.net/2016/04/02/go-1-7-toolchain-improvements Go 1.7 toolchain improvements
267-
.link http://dave.cheney.net/2016/09/18/go-1-8-performance-improvements-one-month-in Go 1.8 performance improvements
268-
269271
## Discussion
270272

271273
Any questions?
272274

273275
[0]: https://www.youtube.com/watch?v=yKQOunhhf4A&index=16&list=PLq2Nv-Sh8EbZEjZdPLaQt1qh_ohZFMDj8
274276
[1]: https://dave.cheney.net/paste/concurrency-made-easy.pdf
275277
[2]: https://golang.org/pkg/bytes
276-
[3]: https://golang.org/pkg/strings
278+
[3]: https://golang.org/pkg/strings
279+
[4]: https://github.com/oklog/run
280+
[5]: https://github.com/heptio/workgroup

0 commit comments

Comments
 (0)