Re: [go-nuts] Re: Why is there a slow-down to split one method of a struct pointer into two methods?

2017-10-08 Thread Jan Mercl
On Sun, Oct 8, 2017 at 8:02 PM Zack Scholl  wrote:

> Why does it slow down the code if its not inlined? Since the method is on
a pointer struct I assume it wouldn't need to copy anything?

Call/return is not free even before stack limit checking, pushing the
arguments and retrieving the return values.


-- 

-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.


[go-nuts] Re: Why is there a slow-down to split one method of a struct pointer into two methods?

2017-10-08 Thread Zack Scholl
Why does it slow down the code if its not inlined? Since the method is on a 
pointer struct I assume it wouldn't need to copy anything?

I'd like to not use inlining because I need the code of this function to be 
used by two different functions and would rather not have to update the 
code twice each time its needed.

Thanks for the io.Writer idea, I'll look into that!

On Sunday, October 8, 2017 at 7:26:58 AM UTC-5, Uli Kunitz wrote:
>
> A function call per input byte will slow your code down unless the 
> function is inlined. The for loop is quite simple so I wonder why you want 
> to separate it. You should also think about whether you want to replace the 
> process method by a Write method, making your object an io.Writer and much 
> more universal.
>
>

-- 
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.


[go-nuts] Re: Why is there a slow-down to split one method of a struct pointer into two methods?

2017-10-08 Thread as
Take the loop and put it inside the function call. Don't make function 
calls in the body of a hot loop, take advantage of the loop optimizations 
in the runtime and your cpu cache.

On Sunday, October 8, 2017 at 3:57:04 AM UTC-7, Zack Scholl wrote:
>
> Why is it that when I a method on an struct pointer, like
>
> func (s *Object) process(inputs []byte) {
> for _, i := range inputs {
> // Lots of code
> }
> }
>
> it will slow down *a lot* if I move // Lots of code to its own function? 
> I.e. I reorganize the above program two use two methods,
>
> func (s *Object) process(inputs []byte) {
> for _, i := range inputs {
> processInput(i)
> }
> }
>
> func (s *Object) processInput(i byte) {
> // Lots of code
> }
>
> This new code runs 30% slower now! 
>
> Why? 
>
> This matters because I'm in a situation in *pluck* where I need // Lots 
> of code in two places. You can reproduce this in *pluck* by running
>
>
> go get -u github.com/schollz/pluck
> cd $GOPATH/src/github.com/schollz/pluck/pluck
> git checkout ef1004f && go test -bench=Stream -run=z
> git checkout 76c4e96 && go test -bench=Stream -run=z
> git diff 76c4e96 ef1004f # shows that I replace lots of code with one 
> 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Why is there a slow-down to split one method of a struct pointer into two methods?

2017-10-08 Thread Uli Kunitz
A function call per input byte will slow your code down unless the function 
is inlined. The for loop is quite simple so I wonder why you want to 
separate it. You should also think about whether you want to replace the 
process method by a Write method, making your object an io.Writer and much 
more universal.

-- 
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.