FAQ
Hello

I found that using value-type named return variables in an outer function
incurs a performance penalty even if it does nothing with those variables
and only calls the inner function.

The benchmark code is here: http://play.golang.org/p/-Dp4oeHd3k

# go test -bench=Outer nrv
BenchmarkSlowOuter 50000000 38.6 ns/op
BenchmarkFastOuter 50000000 27.7 ns/op

// disabled inlining
# GCFLAGS="-l" go test -bench=Outer nrv
BenchmarkSlowOuter 50000000 39.0 ns/op
BenchmarkFastOuter 50000000 28.0 ns/op

// disabled inlining and 'optimizations'
# GCFLAGS="-l -N" go test -bench=Outer nrv
BenchmarkSlowOuter 50000000 39.0 ns/op
BenchmarkFastOuter 100000000 28.0 ns/op

My guess is that we instantiate the value struct, even though it isn't
touched in the outer function.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Dan Kortschak at Jan 31, 2013 at 6:48 pm
    This is issue 3315.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dan Kortschak at Jan 31, 2013 at 6:44 pm
    Sorry, completely wrong there.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Bryanturley at Jan 31, 2013 at 7:03 pm

    On Thursday, January 31, 2013 8:48:31 AM UTC-6, Gustav Paul wrote:
    Hello

    I found that using value-type named return variables in an outer function
    incurs a performance penalty even if it does nothing with those variables
    and only calls the inner function.

    The benchmark code is here: http://play.golang.org/p/-Dp4oeHd3k

    # go test -bench=Outer nrv
    BenchmarkSlowOuter 50000000 38.6 ns/op
    BenchmarkFastOuter 50000000 27.7 ns/op

    // disabled inlining
    # GCFLAGS="-l" go test -bench=Outer nrv
    BenchmarkSlowOuter 50000000 39.0 ns/op
    BenchmarkFastOuter 50000000 28.0 ns/op

    // disabled inlining and 'optimizations'
    # GCFLAGS="-l -N" go test -bench=Outer nrv
    BenchmarkSlowOuter 50000000 39.0 ns/op
    BenchmarkFastOuter 100000000 28.0 ns/op

    My guess is that we instantiate the value struct, even though it isn't
    touched in the outer function.
    Did you check the assembly?

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Russ Cox at Feb 3, 2013 at 5:35 pm
    Thanks. golang.org/issue/4750

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 31, '13 at 2:48p
activeFeb 3, '13 at 5:35p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase