goplus / gop

The Go+ programming language is designed for engineering, STEM education, and data science
https://goplus.org
Apache License 2.0
8.88k stars 547 forks source link

gop compiler is much slower than go #1710

Open sqhua opened 5 months ago

sqhua commented 5 months ago

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%

xushiwei commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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系统的某些调用还能再优化

xushiwei commented 4 months ago

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 commented 4 months ago

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

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 commented 4 months ago

This optimization is not related to windows.