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

Implemented a netvar offset cache #2

Merged
merged 1 commit into from Jan 8, 2017
Merged

Implemented a netvar offset cache #2

merged 1 commit into from Jan 8, 2017

Conversation

sakura57
Copy link
Contributor

@sakura57 sakura57 commented Jan 7, 2017

Being a performance freak I was curious why you call NetVars::GetOffset continually at runtime as opposed to finding needed offsets during initialization then referring to those later.

I realized that GetOffset could probably be modified to cache values to get a similar performance benefit without having to rewrite much existing code.

Here are some comparisons of cached vs uncached. Each time value is for running NetVars::GetOffset("CBasePlayer", "m_vecPunchAngle") 5x in a row. The first result being slower is due to construction of the static unordered_map plus having to realloc. (could probably add a reserve() in there to optimize)

Otherwise it seems to have resulted in about a 10x speedup over the original, which is pretty decent. It might be slightly less than 10x in practice since this was just one offset in the cache, but still a pretty good improvement.

Cached offset finding: 31731 ns
Uncached offset finding: 52452 ns
Cached offset finding: 2770 ns
Uncached offset finding: 36096 ns
Cached offset finding: 2769 ns
Uncached offset finding: 32749 ns
Cached offset finding: 2734 ns
Uncached offset finding: 30897 ns
Cached offset finding: 4127 ns
Uncached offset finding: 217311 ns
Cached offset finding: 2751 ns
Uncached offset finding: 29702 ns
Cached offset finding: 2734 ns
Uncached offset finding: 29024 ns
Cached offset finding: 2766 ns
Uncached offset finding: 29133 ns
Cached offset finding: 2732 ns
Uncached offset finding: 29229 ns
Cached offset finding: 2709 ns
Uncached offset finding: 29210 ns

@aixxe aixxe merged commit ac03e2e into aixxe:master Jan 8, 2017
@aixxe
Copy link
Owner

aixxe commented Jan 8, 2017

Merged, thanks for your contribution.

I've moved a few things around in d3ed740 since I wasn't able to unload the library without any changes.

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.

None yet

2 participants