Go compiler tricks -
i read in talk go compiler aggressively remove code isn't used in output binary. talk can't find used adding code useful testing. have more info on how works? there talks on advanced testing techniques?
five things create go fast
dave cheney
dead code elimination
func test() bool { homecoming false } func expensive() { if test() { // expensive } }
in example, although function test returns false, expensive cannot know without executing it.
when test inlined, this
func expensive() { if false { // expensive // unreachable } }
the compiler knows expensive code unreachable.
not save cost of calling test, saves compiling or running of expensive code unreachable.
for example, adding code useful testing,
func complicated() { if test() { // testing } }
switching test
from
func test() bool { homecoming false }
inlined
func complicated() { if false { // testing // unreachable } }
to
func test() bool { homecoming true }
inlined
func complicated() { if true { // testing // reachable } }
can useful include code testing.
go
No comments:
Post a Comment