https://github.com/orisano/unroller
https://github.com/orisano/unroller
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/orisano/unroller
- Owner: orisano
- License: mit
- Created: 2023-06-13T03:44:00.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-06-06T13:36:09.000Z (about 1 year ago)
- Last Synced: 2025-06-30T03:52:43.153Z (about 1 year ago)
- Language: Go
- Size: 28.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unroller
unroller is a tool for loop unrolling in Go. It generates unrolled versions of functions by adding comments to the top-level for loops.
Loop unrolling is an optimization technique where the compiler expands the iterations of a loop, reducing the overhead of iteration. This can improve the execution speed of the code.
## Installation
To install unroller, you need to have Go installed and set up. Then, you can use the following `go install` command:
```shell
go install github.com/orisano/unroller@latest
```
## Usage
unroller is intended to be used with `go generate`. To generate an unrolled version of a file, add the comment `//go:generate unroller` to the file. For each function that you want to unroll, add the comment `// UNROLL` immediately before the corresponding for loop. When you run `go generate` on that file, unroller will generate a new file with the name `{filename}_unrolled.go`. You can use the `-o` option to specify a different output file name.
Example usage in a file:
```go
//go:generate unroller -o unrolled_file.go
package main
import "fmt"
func foo() {
fmt.Println("start")
// UNROLL
for i := 0; i < 5; i++ {
fmt.Println(i)
}
fmt.Println("end")
}
```
To generate the unrolled version, run the following command:
```shell
go generate path/to/your/file.go
```
The generated unrolled file will have the following content:
```go
// Code generated by unroller. DO NOT EDIT.
package main
import "fmt"
func fooUnrolled() {
fmt.Println("start")
{
const i = 0
fmt.Println(i)
}
{
const i = 1
fmt.Println(i)
}
{
const i = 2
fmt.Println(i)
}
{
const i = 3
fmt.Println(i)
}
{
const i = 4
fmt.Println(i)
}
fmt.Println("end")
}
```
You can then use the generated unrolled file in your codebase.
It's important to note that the `// UNROLL` comment should be placed immediately before the for loop that you want to unroll. Also, remember to include the `//go:generate unroller` comment at the top of the file to ensure that the unrolling process is triggered when running go generate.
## Limitations
* unroller currently supports only top-level for loops. Nested loops are not supported.
## Contributing
Contributions to unroller are welcome! If you find a bug or have a suggestion, please open an issue on the GitHub repository.
## License
unroller is licensed under the MIT License. See the LICENSE file for more information.