If I plan on accessing a certain ConVar value repeatedly, say on a think hook, or even a draw hook - would it be faster to set the new ConVar value on a localized variable and use that instead, or will that have no speed benefit?
performance wise? Nothing that you would ever notice
If you really want to micro-optimize, you can cache the values and refresh them every 1/6 of a second or something. For things like crosshairs that use a lot of convars and aren't changed too often, this would probably be the best solution, but even if you don't the performance cost probably won't be too noticable.
Pretty hard performance impact.
Use local variable + callback instead.
local convar = CreateConVar("test_convar", 5, FCVAR_ARCHIVE)
local temp = nil
local alternative = 5
local now = SysTime()
for k=0, 100000 do
temp = convar:GetInt()
end
MsgN("ConVar time: ",SysTime() - now)
now = SysTime()
local now = SysTime()
for k=0, 100000 do
alternative = 5
end
MsgN("Manual assigment time: ",SysTime() - now)
Accessing 100k times a convar by it return
ConVar time: 0.0066550221105217
Manual assigment time: 9.4952056997499e-05
https://i.imgur.com/ymAgeuV.png
Other cases:
Writing in FCVAR_ARCHIVE:
ConVar time: 0.11833663855452
Manual assigment time: 9.5262357831416e-05
Without FCVAR_ARCHIVE:
ConVar time: 0.11539622779685
Manual assigment time: 0.00010395078129477
Read no cache
ConVar time: 0.0085528220465676
Manual assigment time: 9.1538747710729e-05
Writing no cache
ConVar time: 1.4873982174456
Manual assigment time: 0.00012815424702239
This is not a real world test, but it gives you an idea that it doesn't matter that much, but cache your convars
Sorry, you need to Log In to post a reply to this thread.