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

gop compiler is much slower than go #1710

Open
sqhua opened this issue Feb 5, 2024 · 6 comments
Open

gop compiler is much slower than go #1710

sqhua opened this issue Feb 5, 2024 · 6 comments

Comments

@sqhua
Copy link

sqhua commented Feb 5, 2024

when gop build The following program a.gop triggers an long long time

// a.gop
package main

func main() {
    println("Hello world")
}

gop use over 5 sec, and 'go build' only use 1 sec

E:\gop-1.1.13\bin>gop build a.gop
2024/02/05 22:23:50 profile: cpu profiling enabled, cpu.pprof
2024/02/05 22:23:55 profile: cpu profiling disabled, cpu.pprof

Got

gop build

Gop Version

1.1.13或1.2都试过

Additional Notes

在Win10、Win7都试过。我认为go+语言很好,但也不至于编译性能与go相比下降这么多,是不是我这边的环境问题?为了检查性能,我修改了gop.go代码,加上了pprof,但看不出什么问题。
a.cpuprofile

runtime.cgocall
C:\Program Files\Go\src\runtime\cgocall.go

Total: 12.07s 12.07s (flat, cum) 99.83%

@sqhua sqhua changed the title gop.exe不管是执行run还是build都很慢:go.exe只需要不到1秒,gop.exe要5秒以下 gop.exe不管是执行run还是build都很慢:go.exe只需要不到1秒,gop.exe要5秒以上 Feb 5, 2024
@xushiwei xushiwei changed the title gop.exe不管是执行run还是build都很慢:go.exe只需要不到1秒,gop.exe要5秒以上 gop is much slower than go Feb 6, 2024
@xushiwei xushiwei added this to the Go+ v1.3 milestone Feb 6, 2024
@xushiwei xushiwei changed the title gop is much slower than go gop compiler is much slower than go Feb 6, 2024
@xushiwei
Copy link
Member

xushiwei commented Feb 6, 2024

This is mainly due to the performance of the import function (by https://pkg.go.dev/golang.org/x/tools). This has been solved before, but the burden was relatively heavy, so we gave up the optimization later. After v1.2.0 is released, we will pick up performance optimization again.

这个主要是由于 import 功能的性能导致,这个之前曾经解决过,但是负担比较重所以后来放弃了优化,在 v1.2.0 发布后,接下来我们会把性能优化重新捡起来。

@xushiwei
Copy link
Member

xushiwei commented Feb 6, 2024

I use a mac, but it's not as exaggerated as you said. There may be other reasons why Windows is slow.

% cat t.gop

age := 10
echo "age = ${age}"

% time gop run t.gop

age = 10

gop run t.gop 0.39s user 0.85s system 85% cpu 1.448 total

@sqhua sqhua closed this as completed Feb 6, 2024
@sqhua
Copy link
Author

sqhua commented Feb 6, 2024

Thank you for your reply, Xu Da. I also tested on Win10's WSL, and the performance was slightly better. Here are the results:

>> time gop build a.gop

real    0m2.585s
user    0m0.512s
sys     0m0.912s

Then I tested the same command using PowerShell:

>> Measure-Command {gop build a.gop}

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 5
Milliseconds      : 405
Ticks             : 54051775
TotalDays         : 6.25599247685185E-05
TotalHours        : 0.00150143819444444
TotalMinutes      : 0.0900862916666667
TotalSeconds      : 5.4051775
TotalMilliseconds : 5405.1775

感谢许大的回复,我也在Win10的WSL下做了测试,性能稍好一些,如下:

time gop build a.gop

real 0m2.585s
user 0m0.512s
sys 0m0.912s

然后我用PowerShell再做了同样命令的测试,如下:

Measure-Command {gop build a.gop}

Days : 0
Hours : 0
Minutes : 0
Seconds : 5
Milliseconds : 405
Ticks : 54051775
TotalDays : 6.25599247685185E-05
TotalHours : 0.00150143819444444
TotalMinutes : 0.0900862916666667
TotalSeconds : 5.4051775
TotalMilliseconds : 5405.1775

我没开杀毒软件,推测可能gop对Win系统的某些调用还能再优化

@sqhua sqhua reopened this Feb 6, 2024
@xushiwei
Copy link
Member

The compilation speed of the latest version of Go+ has also been improved a lot. Compiling the complete Go+ tutorial (https://github.com/goplus/tutorial) has been increased by 50 times, and compiling all examples from the spx repository (https://github.com/goplus/spx) is also 10x faster.

At present, two things related to import are mainly optimized: 1) share importer, so that all projects import the same pkg only happen once. 2) Significantly improve the performance of Go+ init package and reduce a large number of unnecessary repeated checks.

@sqhua
Copy link
Author

sqhua commented Feb 18, 2024

我通过源码编译的新版本,似乎性能没有变化,很奇怪:

PS D:\gop-1.2.2\bin> gop version
gop v1.2.2 windows/386

PS D:\gop-1.2.2\bin> Measure-Command {gop build a.gop}
TotalSeconds : 6.0107325

@xushiwei
Copy link
Member

This optimization is not related to windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants