Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: goroutine heavy Go program faster when printing, slower when not #20788

Closed
faiface opened this issue Jun 24, 2017 · 4 comments
Closed

Comments

@faiface
Copy link

faiface commented Jun 24, 2017

Hi!

I'm encountering a weird performance behaviour with Go, possibly due to Go's goroutine scheduler.

Here's my code: https://play.golang.org/p/a1464VZuIb

I'm sorry if it's a bit long, but I couldn't replicate this behaviour with anything shorter. The code basically generates all logic expressions with not and implication logic operators given a certain sequence of logic variables. It does so using goroutines as iterators and recursion. Then it prints all of the tautologies among them.

The bug is that when I comment out the fmt.Println call on the line 89, the program finishes in ~3s. When I uncomment it, it finishes in ~2s. So, when printing, it's significantly faster.

I am using:
go version go1.7.6 linux/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"

@ALTree
Copy link
Member

ALTree commented Jun 24, 2017

I can't reproduce this on go1.7, nor on tip. I'm, too, on linux/amd64. On my machine, the code is slightly faster when you don't print.

Can you reproduce this in go1.9beta? go1.7, at this point, is quite old.

@ALTree ALTree changed the title performance bug: goroutine heavy Go program faster when printing, slower when not runtime: goroutine heavy Go program faster when printing, slower when not Jun 24, 2017
@faiface
Copy link
Author

faiface commented Jun 24, 2017

Ok, so I tried with go1.9beta1 and yes, I can replicate it, but I figured that it only happens in VSCode terminal. When I run the program in normal terminal outside VSCode, the performance is as expected. But inside the VSCode terminal, the performance with printing is faster. This is probably not serious, but very mysterious anyway.

@ALTree
Copy link
Member

ALTree commented Jun 24, 2017

Thanks for checking go1.9.

Sounds like this may be a bug in VSCode's terminal, then?

@faiface
Copy link
Author

faiface commented Jun 24, 2017

Possibly, yeah. Not sure how such bug can exist, but it sounds like that.

@faiface faiface closed this as completed Jun 24, 2017
@golang golang locked and limited conversation to collaborators Jun 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants