Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: better optimization/inlining for sort.Search #43423

Open
yangwenmai opened this issue Dec 29, 2020 · 1 comment
Open

cmd/compile: better optimization/inlining for sort.Search #43423

yangwenmai opened this issue Dec 29, 2020 · 1 comment
Assignees
Milestone

Comments

@yangwenmai
Copy link
Contributor

@yangwenmai yangwenmai commented Dec 29, 2020

What version of Go are you using (go version)?

$ go version
go 1.15.6

Does this issue reproduce with the latest release?

go 1.15.6

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

When I use a helper func SearchLineInfos() and SearchFiles similar as searchInts(), I test those func benchmark

benchmark result:

name               old time/op  new time/op  delta
SearchLineInfos-8  20.7ns ±19%   6.0ns ± 2%  -70.98%  (p=0.000 n=10+10)
SearchFiles-8      9.48ns ±19%  3.22ns ± 1%  -66.05%  (p=0.000 n=10+8)

CL: https://go-review.googlesource.com/c/go/+/279447

What did you expect to see?

In position.go, we impl helper func for sort.Search.

What did you see instead?

if i := sort.Search(len(f.lines), func(i int) bool { return f.lines[i] > offset }) - 1; i>= 0 {
	line, column = i+1, offset-f.lines[i]+1
}

...

Remove func searchInts(a []int, x int) int

cc @mdempsky

@yangwenmai yangwenmai changed the title go/token: maybe we an improve compiler smarter about inlining sort.Search go/token: maybe we can improve compiler smarter about inlining sort.Search Dec 29, 2020
@mdempsky mdempsky self-assigned this Dec 29, 2020
@mdempsky mdempsky added this to the Go1.17 milestone Dec 29, 2020
@mdempsky mdempsky changed the title go/token: maybe we can improve compiler smarter about inlining sort.Search cmd/compile: better optimization/inlining for sort.Search Dec 29, 2020
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Dec 29, 2020

So sort.Search is a relatively simple function that takes a function argument and then calls it at exactly one call site. The compiler should be able to discount the cost of inlining when sort.Search is called with an inlinable function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.