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

sha256 hash function on Windows in Godot 3.4 takes close to 10x as long as it does to 3.3 #55193

Closed
rickwillcox opened this issue Nov 21, 2021 · 7 comments

Comments

@rickwillcox
Copy link

rickwillcox commented Nov 21, 2021

Godot version

3.4

System information

Windows10

Issue description

If I run this code on 3.3 / 3.4 linux or 3.3 windows, I get about 600ms taken to finish hashit().
If I run the same code (same project even), in 3.4 windows it takes around 5550ms to finish hashit()
I have tested this on two machines and also my friend has the same result. We found the bug in our project when we tried to move to 3.4.

func _ready() -> void:
	hashit()

func hashit():
	var start : int = OS.get_system_time_msecs()
	var string : String = "string to hash"
	var ROUNDS : int = pow(2,18)
	var rounds : int = ROUNDS
	while rounds > 0:
		string = string.sha256_text()
		rounds -= 1
	print("sha256 hash run %d times and took %dms" % [ROUNDS, OS.get_system_time_msecs()-start])

Steps to reproduce

run the code on 3.4 windows
compare to time on 3.3 windows

Minimal reproduction project

testhash.zip

@rickwillcox rickwillcox changed the title sha256 hash function on Windows 3.4 takes close to 10x as long sha256 hash function on Windows 3.4 takes close to 10x as long as it does to 3.3 Nov 21, 2021
@Calinou
Copy link
Member

Calinou commented Nov 21, 2021

@rickwillcox Can you reproduce this in any of the 3.4 betas and RCs to determine when the regression started?

I can't reproduce this on Linux on an i7-6700K.

3.3.4.stable (official editor build)

sha256 hash run 262144 times and took 503ms

3.4.stable (official editor build)

sha256 hash run 262144 times and took 509ms

3.5.beta.custom_build [a1ebcbc] (own editor build with target=release_debug use_lto=yes)

sha256 hash run 262144 times and took 527ms

@rickwillcox
Copy link
Author

We tested it the day 3.4 was released. We are not continuing with this implementation but thought the godot team should know.

@rickwillcox
Copy link
Author

This issue is only on WINDOWS 3.4. Linux 3.3 /3.4 and WINDOWS 3.3 work fine.

@akien-mga
Copy link
Member

String.sha256_text() calls CryptoCore::sha256(), which calls into mbedtls_sha256_ret. So this might be related to a mbedtls version update, like Mbed-TLS/mbedtls#4814. CC @Faless

@rickwillcox Could you test Godot 3.2.2 and 3.2.3 too? If my hunch is right, then 3.2.3 should be the first version with this regression, 3.2.2 should be fine (mbedtls 2.16.11 and 2.16.10 respectively).

@akien-mga akien-mga changed the title sha256 hash function on Windows 3.4 takes close to 10x as long as it does to 3.3 sha256 hash function on Windows in Godot 3.4 takes close to 10x as long as it does to 3.3 Nov 22, 2021
@rickwillcox
Copy link
Author

I've uploaded the file test file and code. I dont have time to test further.

@KoBeWi
Copy link
Member

KoBeWi commented May 4, 2022

I checked with 3.2.2, 3.2.3 and 3.5 beta5. The MRP took 790-820 ms to execute, with no big differences between versions.
Tested on Windows 10

@akien-mga
Copy link
Member

Assuming fixed, as we updated mbedTLS from 2.16.11 to 2.28.0 between 3.4 and 3.5, which might have solved potential performance regressions in 2.16. Please comment if you can still reproduce the issue so we can investigate further.

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

5 participants