Raised This Month: $12 Target: $400
 3% 

[CS:GO] Optimizing function


Post New Thread Reply   
 
Thread Tools Display Modes
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
Miu
Veteran Member
Join Date: Nov 2013
Old 09-05-2015 , 16:44   Re: [CS:GO] Optimizing function
Reply With Quote #2

use tries or cache values for each ingame player
Miu is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 09-05-2015 , 17:32   Re: [CS:GO] Optimizing function
Reply With Quote #3

PHP Code:
public Native_GetBestRound(Handle:pluginnumParams)
{
    new 
client GetNativeCell(1);
    new 
style GetNativeCell(2);
    new 
track GetNativeCell(3);
    
    new 
String:auth[32];
    if (!
GetClientAuthString(clientauthsizeof(auth))) {
        return 
false;
    }
    
    new 
size GetArraySize(g_hCache[style][track]);
    for (new 
0sizei++)
    {
        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;

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

Is the best you're going to get without modifications outside of those functions, and probably isn't going to save you much at all. The GetArrayArray is indeed going to be expensive (depending on the size of the array) as it has to copy the contents. The best route forwards for these calls would be to have an additional cache in a StringMap keyed on the steamid (I'm going to guess that the current one cannot be easily converted as it is primarily used as an ordered list).
__________________
asherkin is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 09-05-2015 , 17:54   Re: [CS:GO] Optimizing function
Reply With Quote #4

So I would pretty much do a reverse mapping?
player -> g_hCache[style][track][i]
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 09-05-2015 , 18:39   Re: [CS:GO] Optimizing function
Reply With Quote #5

Yes.
__________________
asherkin is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 09-06-2015 , 17:30   Re: [CS:GO] Optimizing function
Reply With Quote #6

Thanks, that seems to have done the trick.
Calls to the natives now take ~0.000006 seconds and don't lag anymore.
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 09-07-2015 , 08:47   Re: [CS:GO] Optimizing function
Reply With Quote #7

Sweet.
__________________
asherkin is offline
aeleos
Member
Join Date: Sep 2014
Old 09-07-2015 , 16:36   Re: [CS:GO] Optimizing function
Reply With Quote #8

Quote:
Originally Posted by pcmaster View Post
So I would pretty much do a reverse mapping?
player -> g_hCache[style][track][i]
Hey, I am trying to optimize my timer too as I have been noticing the sv to be getting pretty bad recently. Do you think you could go into a little more detail on what you did? I am having a hard time understanding it.
__________________
aeleos is offline
ImACow
AlliedModders Donor
Join Date: Feb 2015
Old 09-11-2015 , 13:55   Re: [CS:GO] Optimizing function
Reply With Quote #9

How does one profile a plugin ? the wiki doesn't help me
ImACow is offline
zipcore
Veteran Member
Join Date: Mar 2010
Location: m_flZipcore
Old 09-12-2015 , 20:27   Re: [CS:GO] Optimizing function
Reply With Quote #10

Quote:
Originally Posted by pcmaster View Post
So I would pretty much do a reverse mapping?
player -> g_hCache[style][track][i]
Thats what I would suggest you aswell.
__________________
zipcore is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode