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

Optimize ENTITY:FireBullets #339

Merged
merged 2 commits into from
Nov 9, 2024
Merged

Optimize ENTITY:FireBullets #339

merged 2 commits into from
Nov 9, 2024

Conversation

Astralcircle
Copy link
Contributor

table.HasValue is much slower than table[x]

@FPtje
Copy link
Owner

FPtje commented Nov 9, 2024

When I saw the PR this morning, I was thinking: Is this very old code, meaning that I wrote it when I didn't fully understand the performance difference between indexing and table.HasValue, or was it written relatively recently, where I figured having a small table with constants might have a faster constant speed with table.HasValue because the hashing of indexing would not be necessary?

Judging by the commit date, this goes all the way back to the initial commit in 2012, which means it's written somewhere between 2007 and 2012 when FPP still used SVN.

Whichever one is faster in this very particular case I'm not entirely sure. With big tables, indexing is definitely faster. With a small table containing just four constants, the iteration might just be ahead of the curve. If you want to hyperoptimize, you could even get rid of the table in favor of just an if-statement like this:

if tracerName == "particleeffect" or tracerName == "smoke" or tracerName == "vortdispel" or tracerName == "helicoptermegabomb" then
    bullet.tracerName = ""
end

Either way, whichever one is faster doesn't really matter. I don't think this code is anywhere near a bottleneck. It's very likely already fast enough that optimizing it will never make a visible difference. Especially when there's some other code that freezes the whole game for seconds.

As such, I'll happily accept this PR and say thank you kindly! It looks better, it may give better performance, and I value the contribution in and of itself!

Thank you!

@FPtje FPtje merged commit b34dd41 into FPtje:master Nov 9, 2024
1 check passed
@Astralcircle Astralcircle deleted the patch-1 branch November 9, 2024 11:54
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