This is a consequence of the decision to keep function pointers as single-word values.
Discussion was here https://groups.google.com/forum/#!msg/golang-dev/G-uGL-jpOFw/pEFi6tsdkdUJ https://groups.google.com/d/msg/golang-dev/x328N8hiN5k/i5LJIXGmi_gJ I *think* that the current implementation was inspired by Minux's comment here: https://groups.google.com/d/msg/golang-dev/G-uGL-jpOFw/vfazKS47_ckJ but I can't seem to find a comment from Russ that I seem to remember where that's specifically acknowledged. On 22 August 2017 at 13:04, Jan Mercl <0xj...@gmail.com> wrote: > On Tue, Aug 22, 2017 at 1:35 PM MartinG <gar...@gmail.com> wrote: > > >> In the below code example, setting a function variable to a simple >> function makes no memory allocation and is very fast (<1ns). The case of >> setting the same function variable to a method value is much slower (~30ns) >> and it turns out to be because memory is allocated there. (16 B/op) > > A function variable is a pointer to a variable length structure containing > the function address and the closure of the function. f1's closure is > statically known (and empty) and is allocated once in the text or data > segment, myObj.myMethod's is dynamic (non empty and contains the receiver) > and thus must be created (allocated) at run time. > > -- > > -j > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.