Removing Function Pointers to Optimize Performance
Open
type/enhancement
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
In Go, the use of function pointers can introduce additional performance overhead. Function pointers, while powerful and flexible, can lead to increased execution time and resource consumption due to the way they are handled at runtime.
Here is a simple test.
```
package main
func square(x int) int {
return x * x
}
var squareFunc func(x int) int = square
func main() {
a := 11
square(a)
// squareFunc(a)
}
```
You can see the difference assembles between function pointer and no function pointer.
https://godbolt.org/z/M6dTErT43
### No Function Pointers
### Function Pointers
Contributor guide
Assessment
This issue has not been assessed yet.