pingcap / pingcap/tidb

Removing Function Pointers to Optimize Performance

Open
#64,048 0 comments 0 reactions 0 assignees View on GitHub
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

Image

### Function Pointers

Image

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.