v icon indicating copy to clipboard operation
v copied to clipboard

Cross compiling from linux to windows produces very slow performing binary

Open rcsaquino opened this issue 2 years ago • 4 comments

Describe the bug

Cross compilation (v -prod -os windows) produces a very slow performing binary. Execution time of my loop is ~20ms on v -prod and ~1800ms on v -prod -os windows. That's 90x faster on native compared to cross compiled code. Tried the same on other languages such as rust and go and the performance difference between the compiled and native code is close to none.

Expected Behavior

Cross compiled binary should be near or at par of natively compiled code performance.

Current Behavior

Cross compiled binary, specifically from linux to windows, produces a very slow performing binary.

Reproduction Steps

Create any program that would take a lot of computing power. Test it both on a native and a cross compiled binary. The native one is runs a lot faster that you wouldn't even consider cross compiling.

V version

V 0.3.3 828b809

Environment details (OS name and version, etc.)

V full version: V 0.3.3 278e747.828b809 OS: linux, Ubuntu 22.04.2 LTS Processor: 12 cpus, 64bit, little endian, Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz

Git version: git version 2.34.1 Git vroot status: weekly.2023.12-13-g828b8097 (1 commit(s) behind V master) .git/config present: true

CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

rcsaquino avatar Mar 22 '23 17:03 rcsaquino

Sounds like a problem in the C cross-compiler being used, not V.

Not sure if anything can be done in V to "fix" that.

JalonSolov avatar Mar 22 '23 19:03 JalonSolov

I think other languages like Rust and Go also uses mingw-w64 for cross compilation but as per my testing they don't have the same issue with V.

rcsaquino avatar Mar 22 '23 23:03 rcsaquino

The performance of V on Windows is still a lot to be desired if you write an simple loop of 1 million, it will run well below expectations, this really surprised me when compared to other languages like C# for example.

V

fn main() {
	for i in 0..1000000{
		println('${i}Ok\r')
	}
}

C#

class Program {
	static void Main(){
		for(int i = 0; i <= 1000000; ++i) {
			System.Console.Write(i + "Ok\r");
		}	
	}

}

Results image

Bonus image

d3c0d3d avatar Mar 24 '23 03:03 d3c0d3d

The performance of V on Windows is still a lot to be desired

I agree. Windows version is very unoptimized at this point. Hopefully all gets ironed out in time.

I tried to time your code on my machine and heres what i got:

Native Linux (WSL2): 0.33s user 1.93s system 65% cpu 3.459 total Native Windows: 0.80s user 14.33s system 22% cpu 1:05.82 total Cross compiled (Linux -> Windows): 1.35s user 25.14s system 24% cpu 1:48.33 total

Rust (WSL2): 0.23s user 1.86s system 55% cpu 3.792 total

rcsaquino avatar Mar 24 '23 04:03 rcsaquino