News for hackers. Stuff that matters.
Re:Go 1.14 release notes by Scaevolus on Tuesday February 25, 2020 @02:26PM (#22416408)
Maybe link the changelog instead? https://tip.golang.org/doc/go1.14

Selected changes:

- This release improves the performance of most uses of defer to incur almost zero overhead compared to calling the deferred function directly. As a result, defer can now be used in performance-critical code without overhead concerns.

- Goroutines are now asynchronously preemptible. As a result, loops without function calls no longer potentially deadlock the scheduler or significantly delay garbage collection.

- Per the overlapping interfaces proposal, Go 1.14 now permits embedding of interfaces with overlapping method sets: methods from an embedded interface may have the same names and identical signatures as methods already present in the (embedding) interface. This solves problems that typically (but not exclusively) occur with diamond-shaped embedding graphs. Explicitly declared methods in an interface must remain unique, as before.

Re:Go 1.14 release notes by jhoechtl on Tuesday February 25, 2020 @03:56PM (#22417352)
> Goroutines are now asynchronously preemptible. As a result, loops without function calls no longer potentially deadlock the scheduler or significantly delay garbage collection.

What does that mean in practice? Can I perform expensive calculations in parallel exhausting all cores?

Re:Go 1.14 release notes by diegobernardes on Tuesday February 25, 2020 @04:13PM (#22417517)
This means that the threads can't be blocked forever. The way Go scheduler work is to check during function calls if the current goroutine has executed for some period of time, after that the scheduler will remove the goroutine from the thread and open space for other goroutines to execute. But if you're doing a loop without function calls, imagine a for {}, in this case, the thread will be locked forever. Now with 1.14, this don't happen anymore. In my opinion the expected result will be better tail latencies.
Re:Go 1.14 release notes by tapirl on Tuesday February 25, 2020 @09:42PM (#22419794)
It means the following program will happily exit now.

  package main
  
  import (
    "time"
    "runtime"
  )
  
  func main(){
    for i := runtime.NumCPU(); i > 0; i-- {
      go func() {
        for {}
      }()
    }
    time.Sleep(time.Second)
    println("bye")
  }
Re:Go 1.14 release notes by pansa2 on Tuesday February 25, 2020 @05:08PM (#22417997)
Go has supported running goroutines in parallel since before 1.0, and it’s been the default behaviour since version 1.5, released in 2015.
Re:Go 1.14 release notes by typical182 on Tuesday February 25, 2020 @02:45PM (#22416630)
As far as I understand, I don't think it is officially released as of this moment. (It is getting close, though).

For example, as of now, the standard release note url for 1.14 currently 404s: https://golang.org/doc/go1.14

Re:Go 1.14 release notes by atombender on Tuesday February 25, 2020 @03:35PM (#22417147)
The download page (https://golang.org/dl/) shows 1.14 as the current version.
Re:Go 1.14 release notes by typical182 on Tuesday February 25, 2020 @06:14PM (#22418574)
It looks like it has been released now.
Re:Go 1.14 release notes by dang on Tuesday February 25, 2020 @02:39PM (#22416558)
Ok, we've changed to that URL from https://github.com/golang/go/releases/tag/go1.14. Thanks!
Re:Go 1.14 release notes by e12e on Tuesday February 25, 2020 @04:19PM (#22417566)
> This release improves the performance of most uses of defer to incur almost zero overhead compared to calling the deferred function directly.

Anyone happen to know why there used to be overhead here/what changed?

From my comfortable sofa, it seems that there should be little difference between a defer-ed and direct call?

Re:Go 1.14 release notes by Scaevolus on Tuesday February 25, 2020 @06:30PM (#22418695)
Defers can happen in a loop, so you need a stack for correctness. This change is that the compiler will now automatically inline the defer-ed call so they appear much the same as a direct call at the end of a function if they happen at most once.

The full design doc is here: https://github.com/golang/proposal/blob/master/design/34481-...

> Go 1.13 implements the defer statement by calling into the runtime to push a "defer object" onto the defer chain. Then, in any function that contains defer statements, the compiler inserts a call to runtime.deferreturn at every function exit point to unwind that function's defers.

> We propose optimizing deferred calls in functions where every defer is executed at most once (specifically, a defer may be on a conditional path, but is never in a loop in the control-flow graph). In this optimization, the compiler assigns a bit for every defer site to indicate whether that defer had been reached or not. The defer statement itself simply sets the corresponding bit and stores all necessary arguments in specific stack slots. Then, at every exit point of the function, the compiler open-codes each deferred call, protected by (and clearing) each corresponding bit.

Re:Go 1.14 release notes by tandr on Tuesday February 25, 2020 @05:33PM (#22418238)
defer-ed calls are (in a very simplified way) pushed on a "stack" of methods to be called just before parent function exists. The mechanics of retrieval-call-repeat_if_more_available are cheap, but not free. They have reduced costs of these interactions.