You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can we have a flag like //go: optimize that tells the compiler to do more optimizations for a specific function?
(like loop unrolling, tail call optimization and others)
I know the go compiler is concerned with compilation speed, so it doesn't try to generate the most efficient code.
But in my program, there is one function that takes up more than 30% of the total time, according to pprof, and I can reduce that by more than 20% by manually unrolling the loop, but the function inevitably becomes hard to read.
Optimizing a few functions may slightly increase compilation time, but will make the program run faster, especially when flag is passed to the bottleneck, meanwhile keeping the readability of code.
The text was updated successfully, but these errors were encountered:
As @mpx said, some kind of per-app feedback would work much better than //go:optimize.
Whether a function should be over-optimized depends on how it is used.
You might find that the most costly function is in a package you depend on,
whether a 'go get' package by someone else or a standard library package.
In both cases, you cannot easily edit the source code to add //go:optimize.
On the other hand, a per-build feedback file can list any function from anywhere.
We don't have that as an option today, but neither do we have //go:optimize.
And if we add //go:optimize we are stuck with it forever.
Better to unroll your loops for now and wait for the right long-term solution.
Description
Can we have a flag like
//go: optimize
that tells the compiler to do more optimizations for a specific function?(like loop unrolling, tail call optimization and others)
I know the go compiler is concerned with compilation speed, so it doesn't try to generate the most efficient code.
But in my program, there is one function that takes up more than 30% of the total time, according to pprof, and I can reduce that by more than 20% by manually unrolling the loop, but the function inevitably becomes hard to read.
Optimizing a few functions may slightly increase compilation time, but will make the program run faster, especially when flag is passed to the bottleneck, meanwhile keeping the readability of code.
The text was updated successfully, but these errors were encountered: