Go 1.16 has released many very interesting changes. Here is a brief summary:
russ cos: deprecated.
- https://twitter.com/_rsc/status/1351676094664110082
- https://go-review.googlesource.com/c/go/+/285378
- https://github.com/golang/go/issues/43724
- Support for darwin/arm64
- Issues encountered supporting darwin/arm64
- Apple’s bug: related to signal preemption
- Apple Silicon M1 performance
- But crypto performance is poor
- Release cycle: https://github.com/golang/go/wiki/Go-Release-Cycle
- Compiler bootstrapping process
- Issues encountered supporting darwin/arm64
-
Installing Go: https://gist.github.com/Dids/dbe6356377e2a0b0dc8eacb0101dc3a7
-
https://github.com/golang/go/issues/42684
- Kernel Panic Episode 62: Your Computer Isn’t Yours, Code Signing, OCSP Server
- Ken Thompson Turing Award lecture: Reflections on Trusting Trust
- TODO
- Apple’s long-standing code signing issues; I encountered similar problems doing Electron in the early days, and these issues still exist today
-
Asynchronous preemption random crashes, a Rosetta bug: https://github.com/golang/go/issues/42700
-
Bootstrapping, installation confusion: https://github.com/golang/go/issues/38485#issuecomment-735360572
- Go’s bootstrapping consists of three steps
-
- 1.4 C version TODO
-
- tool chain 1
-
- tool chain 2
-
- tool chain 3
-
- Go’s bootstrapping consists of three steps
-
Run x86 programs under Rosetta:
arch --x86_64 -
M1 compatibility status in dotfiles: https://github.com/changkun/dotfiles/issues/2
-
Got it in early December, have been using it for almost two months now — very smooth, battery life is incredible
-
My essential third-party software list:
- homebrew (compatibility is not great, but fortunately most dependent software is written in Go, and Go’s support is very complete)
- Breaks compatibility casually, removes software distribution — there was a tool called rmtrash that I had been using since around 2014, but it was removed from distribution last year, so I wrote a fully compatible tool changkun.de/s/rmtrash, but it wasn’t merged; they said it needed to be approved by the original author to bypass popularity restrictions, but the original author is unreachable
- vscode (have been using Insider long-term)
- macvim
- tmux
- oh-my-zsh
- Blender (Cycles ray tracing doesn’t support GPU, but editing meshes with less than a million vertices is fine)
- iTerm: supports M1
- Chrome: supports M1
- MacTex: supports M1
- Docker: released support a week before Christmas, works perfectly, no issues so far
- homebrew (compatibility is not great, but fortunately most dependent software is written in Go, and Go’s support is very complete)
-
Go Modules changes
- Collecting feedback
- Complex dependency management — what’s the most complex project dependency you’ve managed in practice, how many modules, and what do you write for each dependency upgrade? What did you use before Go modules?
- My experience: Go vendor, 1.10 dep, 1.11 go modules
- GOPATH project management — although GOPATH has been removed, I still follow the GOPATH convention
- Minimum version selection
- Semantic Versioning: major.minor.patch
- The classic diamond dependency problem: A depends on B and C, B and C each depend on different versions of D that are incompatible, so no specific version of D can be selected — semantic import versioning eliminates this by adding the major version number requirement at the end of the import path /v2
- dep doesn’t allow diamond dependencies, upgrades are very difficult
- Build reproducibility — without a lock file, >= dependencies change over time
- Select the minimum usable version — builds don’t change over time
- https://www.youtube.com/watch?v=F8nrpe0XWRg&ab_channel=SingaporeGophers
- Misunderstood working methods
- GOPATH
- vendor
- Three key points
- Compatibility
- Reproducibility
- Cooperation (often overlooked by many)
- Go Modules enabled by default, go build must include go.mod file, otherwise compilation fails
- build/test will not upgrade modules
- Default -mod=vendor
-
File system interface
-
Why is the fs.FS abstraction important
- Unix file system abstract always disk blocks
- Network file systems (Upspin) abstract away machines
- REST abstracts nearly anything
- cp doesn’t care whether it’s moving file blocks, or even where the file is — it could be different disks or different machines
- Defines the “generics” for any file type tools
-
What major changes it caused
- io/ioutil
- Russ Cox’s explanation of deprecated in Go (https://twitter.com/_rsc/status/1351676094664110082)
- https://www.srcbeat.com/2021/01/golang-ioutil-deprecated/
- Other fs abstractions
- Rob Pike’s 2016/2017 Gopherfest, Upspin, Changkun’s Midgard
- https://www.youtube.com/watch?v=ENLWEfi0Tkg&ab_channel=TheGoProgrammingLanguage
- FUSE: filesystem in userspace
- https://changkun.de/s/midgard
- Every user has a private root, no global root,
r@golang.org/some/stuff, user names look like email addresses - Access control defined by plain text files
read: r@golang.org, ann@example.com
- Currently a very simple implementation, just a read-only file system
- ReadDir and DirEntry
- Extensible directions: memoryFS, support for writing back to disk, hashFS for CDN support
- Remaining issues… e.g. 44166
1 2 3 4 5 6 7import _ "embed" //go:embed a.txt var s string import "embed" type embed.String string var s embed.String1 - io/ioutil
-
-
File embedding //go:embed
- Basic functionality of the new feature
- Some possible applications
- Some features discussed during the feature freeze cycle
- https://blog.carlmjohnson.net/post/2021/how-to-use-go-embed/
-
Runtime memory management
- Return to MADV_DONTNEED
- New monitoring infrastructure runtime/metrics
- Previous monitoring functions: runtime.ReadMemStats, debug.GCStats
- runtime/metrics:
- metrics.All()
- Issue 37112
|
|
- Other noteworthy features
- os/signal.NotifyContext
- Memory model fixes
- Linker optimizations
Go 1.16 发布了非常多非常有趣的变,尝试做一个简单的总结:
russ cos: deprecated.
- https://twitter.com/_rsc/status/1351676094664110082
- https://go-review.googlesource.com/c/go/+/285378
- https://github.com/golang/go/issues/43724
- 支持 darwin/arm64
- 支持 darwin/arm64 上遇到的问题
- 苹果的bug: 与信号抢占有关
- Apple Silicon M1 性能
- 但是在加密上性能很差
- 发版周期:https://github.com/golang/go/wiki/Go-Release-Cycle
- 编译器自举过程
- 支持 darwin/arm64 上遇到的问题
-
安装 Go:https://gist.github.com/Dids/dbe6356377e2a0b0dc8eacb0101dc3a7
-
https://github.com/golang/go/issues/42684
- 内核恐慌的第 62 期:你的电脑不是你的,代码签名,OCSP Server
- ken thompson 图灵奖演讲:reflections on trusting trust
- TODO
- 苹果代码签名的老问题,早年做 electron 也是这类问题,现在这样的问题还是存在
-
异步抢占随机崩溃,是 Rosetta 的 Bug:https://github.com/golang/go/issues/42700
-
自居,安装的困惑:https://github.com/golang/go/issues/38485#issuecomment-735360572
- Go 语言的自举分为三个步骤
-
- 1.4 C version TODO
-
- tool chain 1
-
- tool chain 2
-
- tool chain 3
-
- Go 语言的自举分为三个步骤
-
在 Rosetta 下运行 x86 程序:
arch --x86_64 -
dotfiles 中关于 M1 的兼容性情况:https://github.com/changkun/dotfiles/issues/2
-
十二月初入手 如今已经使用快两个月了 非常流畅 续航逆天
-
我的必备第三方软件列表:
- homebrew (支持性不好,好在现在大部分依赖的软件是用 Go 写的,而且 Go 的支持非常完善)
- 不考虑兼容性 随意破坏兼容性移除软件分发,有一个 rmtrash 的工具,我从2014年左右就开始使用,但是去年被从软件分发中移除了,所以自己写了一个全兼容的工具changkun.de/s/rmtrash,但没有被合并,他们说了要被原软件作者任何才能不受受欢迎程度的限制,但实际上软件作者已经联系不到了
- vscode(已在长期使用 Insider)
- macvim
- tmux
- oh-my-zsh
- Blender(Cycles 光追渲染不支持 GPU,但编辑顶点小于百万级别的网格是没有问题的)
- iTerm:支持 M1
- Chrome:支持 M1
- MacTex:支持 M1
- Docker:圣诞节前一周发布支持,很完美,至今没有遇到问题
- homebrew (支持性不好,好在现在大部分依赖的软件是用 Go 写的,而且 Go 的支持非常完善)
-
Go Modules 的变更
- 收集反馈
- 复杂依赖管理,你实践中管理过最复杂的项目依赖多少模块,每次依赖升级都有写什么?在没有 Go modules 之前你用的是什么?
- 我的经历:Go vendor, 1.10 dep, 1.11 go modules,
- GOPATH 的项目管理,现在虽然移除了 gopath,但我还是沿用了 gopath 的习惯
- 最小版本选择
- Semantic Versioning: major.minor.patch
- 经典的钻石依赖问题:A依赖B和C,BC分别依赖 D 的不同版本,而这两个版本的 D 不兼容,所以无法在依赖中选取一个特定的D版本,semantic import versioning 消除了这种依赖,在import path的最后添加了主版本号的要求/v2
- dep 不允许钻石依赖,升级非常难
- 构建的可重复性,没有lock文件,>=的依赖会随着时间的变化而变化
- 选择最小的可以依赖的版本,构建不会随时间的变化而变化
- https://www.youtube.com/watch?v=F8nrpe0XWRg&ab_channel=SingaporeGophers
- 不被理解的工作方式
- GOPATH
- vendor
- 三大要点
- 兼容性
- 可重复性
- 合作(通常被很多人忽略)
- 默认启用 Go Moduels, go build 必须包含 go.mod 文件,否则编译失败
- build/test 不会升级 modules
- 默认 -mod=vendor
-
文件系统接口
-
fs.FS 抽象的重要性在哪里
- unix file system abstract always disk blocks
- network file systems (upspin) abstract away machines
- rest abstract nearly anything
- cp 不关心是否移动文件的区块,甚至不关心文件在哪个位置,可能是不同的磁盘也可能是不同的机器
- 定义任何文件类型工具的「泛型」
-
导致了哪些主要变化
- io/ioutil
- Russ cox 对 deprecated 在 go 中的解释(https://twitter.com/_rsc/status/1351676094664110082)
- https://www.srcbeat.com/2021/01/golang-ioutil-deprecated/
- 其他 fs 的抽象
- Rob Pike 的 2016/2017 Gopherfest, Upspin、Changkun 的 Midgard
- https://www.youtube.com/watch?v=ENLWEfi0Tkg&ab_channel=TheGoProgrammingLanguage
- FUSE: filesystem in userspace
- https://changkun.de/s/midgard
- every user has a private root, no global root,
r@golang.org/some/stuff, user names look like email address - access control defined by plain text files
read: r@golang.org, ann@example.com
- 目前的非常简单的实现,只是一个只读文件系统
- ReadDir and DirEntry
- 可扩展的方向:memoryFS,支持回写到磁盘、hashFS 为 CDN 提供支持
- 还存在的问题。。例如 44166
1 2 3 4 5 6 7import _ "embed" //go:embed a.txt var s string import "embed" type embed.String string var s embed.String1 - io/ioutil
-
-
文件嵌入 //go:embed
- 新特性的基本功能
- 一些可能的应用
- 一些在feature freeze cycle 中才讨论出来的feature
- https://blog.carlmjohnson.net/post/2021/how-to-use-go-embed/
-
运行时内存管理
- 回归 MADV_DONTNEED
- 新的监控基础设施 runtime/metrics
- 以前的监控函数:runtime.ReadMemStats, debug.GCStats,
- runtime/metrics:
- metrics.All()
- Issue 37112
|
|
- 其他值得一提的特性
- os/signal.NotifyContext
- 内存模型修复
- 链接器优化