View Single Post
Author Message
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 09-05-2015 , 16:20   [CS:GO] Optimizing function
Reply With Quote #1

So, after doing some profiling on the timer plugin we use (Zipcore's), I have found out that two functions are slowing down the server a lot.
By a lot, I mean ~690µs/player, 5 times per second, causing the server to have svms spikes up to 100.

These two are:

1st:
PHP Code:
public Native_GetBestRound(Handle:pluginnumParams)
{
    new 
client GetNativeCell(1);
    new 
style GetNativeCell(2);
    new 
track GetNativeCell(3);
    
    
decl String:auth[32];
    
GetClientAuthString(clientauthsizeof(auth));
    
    if(
GetArraySize(g_hCache[style][track]) <= 0)
        return 
false;
    
    for (new 
0GetArraySize(g_hCache[style][track]); i++)
    {
        new 
nCache[RecordCache];
        
GetArrayArray(g_hCache[style][track], inCache[0]);
        
        if (
StrEqual(nCache[Auth], auth))
        {
            
SetNativeCellRef(4nCache[Time]);
            
SetNativeCellRef(5nCache[Jumps]);
            return 
true;
        }
    }
    
    return 
false;

2nd:
PHP Code:
public Native_GetStyleRank(Handle:pluginnumParams)
{
    new 
client GetNativeCell(1);
    new 
track GetNativeCell(2);
    new 
style GetNativeCell(3);
    
    
decl String:auth[32];
    
GetClientAuthString(clientauthsizeof(auth));
    
    for (new 
0GetArraySize(g_hCache[style][track]); i++)
    {
        new 
nCache[RecordCache];
        
GetArrayArray(g_hCache[style][track], inCache[0]);
        
        if (
StrEqual(nCache[Auth], auth))
            return 
i+1;
    }
    
    return 
0;

</span>My suspicion is that the GetArrayArray and String-comparison takes a long time.

Is there a way to optimize them somehow? Or do I have to cache their values somhow (altough this will again cause lags when calling them..
Any help is appreciated!
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline