47

GitHub - changkun/go-under-the-hood: Go 源码研究 (1.11.1, WIP)

 5 years ago
source link: https://github.com/changkun/go-under-the-hood
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

logo

Go under the hood

目前基于 go1.11.1

致潜在读者

此仓库的内容可能勾起你的兴趣,如果你想要关注本仓库的更新情况,可以点击仓库的 Watch。 此仓库才刚刚开始,笔者因各方面事情都很忙,并仅刚开始尝试阅读 Go 源码,由于各种不可抗力和一时兴起, 更新可能会很慢(也会很乱,不一定顺序更新内容)。

如果你也希望参与贡献,欢迎提交 issue 或 pr。

为什么要研究源码?

研究 Go 源码有几个初衷:

  1. 出于对技术的纯粹兴趣;
  2. 工作需要,需要了解更多关于 Go 运行时 GC、cgo 等细节以优化性能。

为什么不读现有的源码分析?

确实已经有很多很多讨论 Go 源码的文章了,不读他们的文章有几个原因:

  1. 别人的是二手资料,自己的是一手资料,理解别人理解代码的思路,增加了额外的成本,不如直接理解代码。
  2. 比较完整的资料已经存在一定程度上的过时,Go 运行时的开发是相当活跃的,本仓库目前基于 1.11.1。

那关注什么?

本仓库主要关注与运行时相关的代码,例如 runtime/cgo/sync/net/syscall 等。 在极少数的情况下,会讨论不同平台下的差异,代码实验以 darwin 为基础,linux 为辅助关注点,其他平台几乎不关注。 作为 Go 1.11 起引入的 wasm 特性,我们特别给 WebAssembly 平台以特别关注。

所以,诸如 crypto/database/regexp/strings/strconv/sort/container/unicode 等一些运行时无关的标准库 可能不在研究范围。

目录

  1. 引导
  2. 初始化概览
  3. 主 goroutine 生命周期
  4. 内存分配器
  5. 调度器
  6. 垃圾回收器
  7. 语言特性
  8. 运行时杂项
  9. unsafe
  10. cgo
  11. 依赖运行时的标准库
  12. WebAssembly
  13. 编译前端
  14. 编译后端

环境

→ go version
go version go1.11.1 darwin/amd64
→ uname -a
Darwin changkun-pro 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64

许可

Go under the hood | CC-BY-NC-ND 4.0 & MIT © changkun


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK