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

(Performance) Change static readonly fields to const fields #4211

Conversation

FlaggAC
Copy link
Contributor

@FlaggAC FlaggAC commented Aug 11, 2024

This will at least somewhat improve performance, as confirmed through microbenchmark testing.

const fields are replaced with literal values in the Assembly's IL code, while static readonly fields may be optimized by the JIT, and is not guaranteed to happen. const fields may also lend themselves to stronger optimizations at runtime.

Method is LandDefs.AdjustToOutside.
Baseline (static readonly):

| Method          | Mean     | Error    | StdDev   | Allocated |
|---------------- |---------:|---------:|---------:|----------:|
| AdjustToOutside | 15.90 ns | 0.300 ns | 0.308 ns |         - |

With constants:

| Method          | Mean     | Error    | StdDev   | Allocated |
|---------------- |---------:|---------:|---------:|----------:|
| AdjustToOutside | 13.36 ns | 0.243 ns | 0.227 ns |         - |

This is a 15% improvement for LandDefs.AdjustToOutside. Additionally, I measured through some custom profiler code that LandDefs.AdjustToOutside is called very frequently. So I would estimate this to be a solid improvement.

This will at least somewhat improve performance, as confirmed through microbenchmark testing.

const fields are replaced with literal values in the Assembly's IL code, while static readonly fields may be optimized by the JIT, and is not guaranteed to happen. const fields may also lend themselves to stronger optimizations at runtime.
@gmriggs gmriggs requested a review from Mag-nus August 11, 2024 05:04
@Mag-nus Mag-nus merged commit 7f1b58a into ACEmulator:master Aug 24, 2024
2 checks passed
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