Skip to content

cmd/compile: inline function calls that return a closure #10292

Open
@potocnyj

Description

@potocnyj

https://go-review.googlesource.com/#/c/8200/ added a benchmark to the strings package that shows strings.Trim and its variants allocate memory. The allocation is caused by the call to makeCutsetFunc here. Inlining this call removes the allocation and provides a nice performance boost to Trim. You can see the effect on the benchmark using Go Tip (commit 6262192) below:

benchmark         old ns/op     new ns/op     delta
BenchmarkTrim     3204          2323          -27.50%

benchmark         old allocs     new allocs     delta
BenchmarkTrim     11             0              -100.00%

benchmark         old bytes     new bytes     delta
BenchmarkTrim     352           0             -100.00%

makeCutsetFunc is a pretty simple function (all it does is return a closure), and it was pointed out in review that it might be nice to inline functions like it in the compiler rather than changing strings.Trim explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions