Skip to content

Latest commit

 

History

History
138 lines (90 loc) · 3.78 KB

File metadata and controls

138 lines (90 loc) · 3.78 KB

RoutineX 编译器

Build Status Codecov Go Report Card Documentation Release License

English Version

RoutineX 是一个编译工具,旨在增强Golang标准库中runtime包的协程能力。

作为routine静态模式的编译工具,它支持原生协程级存储(TLS)等高级特性。

这使routine在静态模式下,具有更高的性能、更安全的内存访问机制。

🏠介绍

routine 在普通的模式下,根据结构体布局,将labelMap和协程上下文数据存储在g.labels字段。

这需要再读取和继承时,要做额外的验证和判断,对性能具有一定的影响,并且可能不兼容将来的go版本。

为了进一步提升性能和兼容性,RoutineX编译器通过源码增强技术,在底层导出部分函数, 使routine能高效,安全的访问协程结构g的数据。

🛠️使用说明

安装

go install -a github.com/timandy/routinex@latest

调用前需要设置环境变量,把$(go env GOPATH)/bin追加到PATH,以便在控制台直接运行routinex

  • windows
#!/bin/pwsh

$env:Path="$env:Path;$(go env GOPATH)\bin"
  • linux
#!/bin/bash

export PATH="$PATH:$(go env GOPATH)/bin"

开启调试

使用调试参数可以输出routinex的日志。

  • --debug-d输出详细的日志。

  • --verbose-v输出简略的日志。

  • windows

#!/bin/pwsh

# 设置环境变量
$env:Path="$env:Path;$(go env GOPATH)\bin"
# 添加参数
go build -a -toolexec='routinex -v' -o main.exe .
  • linux
#!/bin/bash

# 设置环境变量
export PATH="$PATH:$(go env GOPATH)/bin"
# 添加参数
go build -a -toolexec='routinex -v' -o main.exe .

多工具链

如果在使用routinex之前已经使用了其他的工具链,以abc为例。

因为不能保证abc有链式传递功能,所以要将routinex放在abc工具链前边。

routinex执行完后,会自动调用abc工具。

  • windows
#!/bin/pwsh

# 设置环境变量
$env:Path="$env:Path;$(go env GOPATH)\bin"
# 添加参数
go build -a -toolexec='routinex -v abc' -o main.exe .
  • linux
#!/bin/bash

# 设置环境变量
export PATH="$PATH:$(go env GOPATH)/bin"
# 添加参数
go build -a -toolexec='routinex -v abc' -o main.exe .

💡实现原理

参见

🚀性能提升

参见

📜许可证

RoutineX是在 Apache License 2.0 下发布的。

Copyright 2021-2025 TimAndy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.