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

feat/rankings: optimize Steam ID comparison #236

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

NeKzor
Copy link
Contributor

@NeKzor NeKzor commented Nov 16, 2024

Since the Steam ID is a 64bit integer we should compare it in registers directly instead of comparing a string byte by byte. The string representation is only needed when constructing the URL to call the profile API and when exporting the data.

It's a µ-optimization so this does not speed up the program too much since the biggest slowdown will always be network requests.

Profiled this small code section:

start := time.Now()

for _, profile := range data.Response.Players {
	for _, player := range players {
		if player.SteamID == profile.SteamID {
			player.AvatarLink = profile.AvatarFull
			player.Username = profile.PersonaName
		}
	}
}

duration := time.Since(start)
fmt.Printf("took: %v\n", duration)
# main
2024/11/16 22:01:23 fetching info for 100 players
took: 262.425µs
2024/11/16 22:01:24 fetching info for 100 players
took: 246.73µs
2024/11/16 22:01:25 fetching info for 92 players
took: 209.21µs

# this pr ~8x faster
2024/11/16 22:05:00 fetching info for 100 players
took: 31.959µs
2024/11/16 22:05:00 fetching info for 100 players
took: 31.688µs
2024/11/16 22:05:01 fetching info for 92 players
took: 26.985µs

@pektezol pektezol merged commit 780bcf4 into pektezol:main Nov 18, 2024
@NeKzor NeKzor deleted the rankings/fast-steam-id-comp branch November 22, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants