github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/go1.3.slide (about)

     1  Toward Go 1.3
     2  (and beyond)
     3  
     4  Andrew Gerrand
     5  Gopher
     6  @enneff
     7  http://golang.org
     8  
     9  
    10  * Go 1.3
    11  
    12  Code freeze is March 1, 2014.
    13  
    14  Release is June 1, 2014.
    15  
    16  (Six months after Go 1.2, released December 1, 2013.)
    17  
    18  
    19  * A to-do list
    20  
    21  After Go 1.2 the Go contributors compiled a to-do list:
    22  
    23  .link http://golang.org/s/go13todo
    24  
    25  The list is aspirational; not all of it will get done.
    26  
    27  This talk is based on that list.
    28  
    29  
    30  * 100% precise GC
    31  
    32  Finally!
    33  
    34  
    35  * Copying stacks (1/2)
    36  
    37  .link http://golang.org/s/contigstacks
    38  
    39  Go 1.2's stack split mechanism has a "hot split" problem.
    40  
    41  Copying (or "contiguous") stacks are grown by reallocation and copying.
    42  Resolves the "hot split" problem.
    43  Makes smaller initial stacks practical - more goroutines in the same space.
    44  
    45  * Copying stacks (2/2)
    46  
    47  .image go1.3/json.png
    48  
    49  
    50  * Dmitry's bag of performance tricks
    51  
    52  Runtime changes:
    53  
    54  - increase page size to 8K (~10% GC less pause time)
    55  - do not collect GC roots explicitly (~6% GC less pause time)
    56  - prefetch next block in mallocgc (~2% less CPU)
    57  - smarter slice grow (2-20% less CPU)
    58  - combine small NoScan allocations (10% faster json benchmark)
    59  - do not zero terminate strings (1% fewer allocs json benchmark)
    60  - remove locks from netpoll hotpaths (~5% faster TCP)
    61  - allocate goroutine ids in batches (8-66% faster goroutine creation)
    62  - use lock-free ring for work queues (5-40% faster goroutine scheduling)
    63  - per-P defer pool (memory savings for programs with many goroutines)
    64  
    65  And many more to come...
    66  
    67  
    68  * Channel rewrite
    69  
    70  .link http://golang.org/s/go13chan
    71  
    72  Goals:
    73  
    74  - make single-threaded (non-contended) channel operations faster
    75  - make contended buffered (producer/consumer) channel operations faster
    76  - make non-blocking failing operations (e.g. checking of "stop" channel) faster
    77  - make chan semaphores (chan struct{}) faster
    78  - make select statements faster
    79  
    80  Non-goals:
    81  
    82  - make channels completely lock-free (this would significantly complicate implementation and make it slower for common cases)
    83  - make contended synchronous channel operations faster
    84  
    85  
    86  * sync.Pool (1/2)
    87  
    88  Many Go libraries include custom thread-safe free lists, like this:
    89  
    90  	var objPool = make(chan *Object, 10)
    91  
    92  	func obj() *Object {
    93  		select {
    94  		case p := <-objPool:
    95  			return p
    96  		default:
    97  		}
    98  		return NewObject()
    99  	}
   100  
   101  	func objPut(p *Object) {
   102  		select {
   103  		case objPool <- p:
   104  		default:
   105  		}
   106  	}
   107    
   108  	p := obj()
   109  	// use p
   110  	objPut(p)
   111  
   112  * sync.Pool (2/2)
   113  
   114  The `sync.Pool` type provides a general thread-safe global free list.
   115  
   116  It allows the runtime to reclaim entries when appropriate
   117  (for example, during garbage collection).
   118  
   119  	var objPool = sync.Pool{
   120  		New: func() interface{} {
   121  			return NewObject()
   122  		},
   123  	}
   124    
   125  	p := objPool.Get().(*Object)
   126  	// use p
   127  	objPool.Put(p)
   128  
   129  This is an experimental type and might not be released.
   130  
   131  
   132  * Native Client port
   133  
   134  .link http://golang.org/s/go13nacl
   135  
   136  Native Client (NaCl) is a restricted execution environment for x86 binaries.
   137  
   138  Notably used to run compiled binaries inside Google Chrome.
   139  NaCl also provides a tool for executing command-line binaries
   140  
   141  Go 1.3 targets that command-line tool for 32-bit and 64-bit x86 architectures.
   142  (NaCl supports 32-bit ARM, but we have no plans to support it.)
   143  
   144  The [[http://play.golang.org][Go Playground]] uses the NaCl tool chain to safely execute untrusted programs.
   145  
   146  The NaCl tool chain includes the fake time, network, and file system capabilities of the playground.
   147  
   148  
   149  * OS ports
   150  
   151  Solaris: work in progress, on track for Go 1.3.
   152  
   153  DragonflyBSD: work is done, looking for a maintainer.
   154  
   155  Plan 9: still not finished.
   156  
   157  darwin/arm, android/arm: a contributor is working on these, some way to go.
   158  
   159  
   160  * The go command and fsnotify
   161  
   162  .link http://golang.org/s/go13fsnotify
   163  
   164  In Go 1.2, `go` `build` stats every dependent source file to see whether they have changed.
   165  
   166  This is a big chunk of total build time.
   167  
   168  The proposed "go background" command starts a daemon that watches source files for changes.
   169  
   170  When building, the `go` commands can ask the daemon which files have changed.
   171  
   172  A new `os/fsnotify` package will be added to the standard library to support the `go` command.
   173  
   174  A proposed interface is discussed here:
   175  
   176  .link http://golang.org/cl/48310043
   177  
   178  
   179  * Support for linking against Objective C code
   180  
   181  The Go 1.2 tool chain can link against C++ code using `cgo` (but you need to write a small C bridge into the C++ code).
   182  
   183  The same can be done for Objective C code, with some modifications to the go tool.
   184  
   185  This will make it easier to write native OS X applications.
   186  
   187  
   188  * Address binary bloat
   189  
   190  .link http://golang.org/issue/6853
   191  
   192  Go binaries are getting pretty big. Rob ran an experiment:
   193  
   194  	As an experiment, I built "hello, world" at the release points for go 1.0. 1.1, and 1.2.
   195  	Here are the binary's sizes:
   196  
   197  	% ls -l x.1.?
   198  	-rwxr-xr-x  1 r  staff  1191952 Nov 30 10:25 x.1.0
   199  	-rwxr-xr-x  1 r  staff  1525936 Nov 30 10:20 x.1.1
   200  	-rwxr-xr-x  1 r  staff  2188576 Nov 30 10:18 x.1.2
   201  
   202  Go binaries contain several sets of debugging symbols (for gdb, profilers, reflection, etc).
   203  
   204  We intend to rationalize these as part of some work on the linker.
   205  Speaking of which...
   206  
   207  
   208  * Linker overhaul (1/3)
   209  
   210  .link http://golang.org/s/go13linker
   211  
   212  The `gc` tool chain is a bit unconventional.
   213  
   214  The compilers don't emit machine code but an intermediate assembly language.
   215  
   216  The linker translates it into machine code.
   217  
   218  The packages can be compiled in parallel by independent runs of the compiler,
   219  but the linking must be done by a single linker process after compilation is complete.
   220  
   221  The `gc` linker has become a bottleneck in building programs
   222  because it does more work than a typical linker.
   223  
   224  * Linker overhaul (2/3)
   225  
   226  The Go 1.2 linker's job can be split into two parts:
   227  
   228  - translate an input stream of pseudo-instructions into executable code, data blocks, and a list of relocations,
   229  - delete dead code, merge what's left, resolve relocations, and generate a few whole-program data structures.
   230  
   231  .image go1.3/liblink1.png
   232  
   233  * Linker overhaul (3/3)
   234  
   235  In Go 1.3, much of the old linker is moved to a `liblink` library that is then used by assemblers and compilers (`6a`, `6c`, `6g`, etc). This allows more work to be done in parallel.
   236  
   237  .image go1.3/liblink2.png
   238  
   239  And because the linker is much simpler now, we can rewrite it in Go.
   240  
   241  
   242  * Compiler overhaul
   243  
   244  .link http://golang.org/s/go13compiler
   245  
   246  The "gc" tool chain is based on the Plan 9 C compilers.
   247  
   248  The assemblers, C compilers, and linkers were lifted wholesale.
   249  
   250  The Go compilers are new C programs that fit into that tool chain.
   251  
   252  Wouldn't it be nice to have a Go compiler written in Go?
   253  
   254  * Compiler overhaul: why C then?
   255  
   256  Many benefits to writing the compiler in C:
   257  
   258  - Go did not exist
   259  - Once Go did exist, it changed often
   260  
   261  Today, Go does exist and is stable as of Go 1.
   262  These benefits not as relevant now.
   263  
   264  * Compiler overhaul: why Go now?
   265  
   266  The benefits of a Go-based compiler:
   267  
   268  - Go code is easier to write and debug
   269  - Go has better support for modularity, automated rewriting, unit testing, and profiling
   270  - Go programmers are more likely to work on a compiler written in Go
   271  - Go code is easier to parallelize
   272  - Go is more fun!
   273  
   274  * Compiler overhaul: the plan
   275  
   276  Not a rewrite.
   277  
   278  Translate the C compilers to Go.
   279  
   280  Write and use an automatic translator to do this.
   281  
   282  Start the process with Go 1.3 and continue in future releases.
   283  
   284  * Compiler overhaul: five phases
   285  
   286  - Develop and debug the translator.
   287  - Translate the C to Go and delete the C code.
   288  - Clean up and document the code, add unit tests. (Target Go 1.4)
   289  - Profile and optimize the compiler and split it into packages.
   290  - Replace the front end with `go/parser` and `go/types`. (Maybe with new versions of those packages.)
   291  
   292  * Compiler overhaul: bootstrapping
   293  
   294  Must have a way to build the compiler from scratch.
   295  
   296  Our plan is that the Go 1.3 compiler must compile using Go 1.2, and Go 1.4 must compile with Go 1.3, and so on.
   297  
   298  Write a shell script to do this automatically. Bootstrap once per machine.
   299  
   300  This scales poorly over time, so we might write a back end for the compiler that generates C code, and keep the C version of the compiler sources checked in.
   301  
   302  * Compiler overhaul: alternatives
   303  
   304  Write new compilers from scratch?
   305  
   306  - The existing compilers are well-tested and handle many subtle cases well; would be foolish to throw away 10 man-years of effort.
   307  
   308  Translate the compiler manually?
   309  
   310  - Translation is tedious and error-prone, mistakes are subtle and hard to find. Can continue to work on existing compilers while writing the translator.
   311  
   312  Translate just the back ends and connect to `go/parser` and `go/types` immediately?
   313  
   314  - The existing APIs are very different; too much work to undertake at once.
   315  
   316  Discard the current compilers and use gccgo (or `go/parser` and `go/types` and LLVM)?
   317  
   318  - The current compilers are a large part of our flexibility. Tying Go to large C/C++ projects like GCC or LLVM hurts that flexibility.
   319  
   320  
   321  * Lots of small things
   322  
   323  As with previous releases, we'll see a long tail of small fixes and changes.