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

Efficient caching method


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 07-23-2016 , 07:48   Efficient caching method
Reply With Quote #1

I'm looking for a fast and reliable caching method.
I have a plugin that uses an individual ArrayList for every client and around 10 extras. Those ArrayLists for individual clients will increase their size by 1 and push 5 float values to the ArrayList every time OnPlayerRunCmd is called, they can be reset every few seconds or even 1 hour.
This will be (and is) degrading the server's performance due to insane increments of the ArrayList.

What's an efficient way of storing such big amounts of data within SourceMod? Thought of using Dynamic but then I'll end up basically creating an infinite amount of handles and that's bad.
__________________
retired

Last edited by shavit; 07-23-2016 at 11:01.
shavit is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 07-23-2016 , 10:22   Re: Efficient caching method
Reply With Quote #2

Why do you think that's degrading performance? o.o
Miu is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-23-2016 , 10:29   Re: Efficient caching method
Reply With Quote #3

Did you profile your code before you came to the conclusion that it is degrading performance?
Potato Uno is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 07-23-2016 , 11:07   Re: Efficient caching method
Reply With Quote #4

Quote:
Originally Posted by Miu View Post
Why do you think that's degrading performance? o.o
server variance is higher when the plugin is off

Quote:
Originally Posted by Potato Uno View Post
Did you profile your code before you came to the conclusion that it is degrading performance?
actually no, i'll do that now
__________________
retired
shavit is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 07-23-2016 , 12:02   Re: Efficient caching method
Reply With Quote #5

Quote:
Originally Posted by shavit View Post
server variance is higher when the plugin is off
The stuff in the OP presumably isn't the only thing the plugin does, so why do you think that's what's causing it?
Miu is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 07-23-2016 , 12:25   Re: Efficient caching method
Reply With Quote #6

Quote:
Originally Posted by Miu View Post
The stuff in the OP presumably isn't the only thing the plugin does, so why do you think that's what's causing it?
ok nvm i had some background process (nginx with a bad config) that killed my cpu, just a coincidence
__________________
retired

Last edited by shavit; 07-23-2016 at 12:25.
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-24-2016 , 07:31   Re: Efficient caching method
Reply With Quote #7

Fyi: GetArraySize is a performance killer as I learnt from Dynamic.
__________________
Neuro Toxin is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 07-24-2016 , 07:57   Re: Efficient caching method
Reply With Quote #8

Quote:
Originally Posted by Neuro Toxin View Post
Fyi: GetArraySize is a performance killer as I learnt from Dynamic.
so instead of array.Length should i create a global variable for the array size and manually increment it every time, or just reduce calls to array.Length?
__________________
retired

Last edited by shavit; 07-24-2016 at 07:58.
shavit is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-24-2016 , 09:18   Re: Efficient caching method
Reply With Quote #9

Quote:
Originally Posted by Neuro Toxin View Post
Fyi: GetArraySize is a performance killer as I learnt from Dynamic.
That doesn't seem right. That's likely the most lightweight native of all ADT Array natives. It just returns one cached value.

Last edited by klippy; 07-24-2016 at 09:18.
klippy is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-24-2016 , 10:15   Re: Efficient caching method
Reply With Quote #10

Quote:
Originally Posted by KliPPy View Post
That doesn't seem right. That's likely the most lightweight native of all ADT Array natives. It just returns one cached value.
Quote:
Originally Posted by shavit View Post
so instead of array.Length should i create a global variable for the array size and manually increment it every time, or just reduce calls to array.Length?
That is even worse for performance.

Doing ++ in pawn is way worse than doing ++ in C++, because every operation on pawn is a bytecode dispatch on the JIT (push parameters to stack, run assembly on the CPU, send results back to pawn... and that's an oversimplification). Anything you do in pawn will be way slower than equivalent code in C++.

If the SM devs coded it properly (I haven't checked, but I am assuming they did), they would have had an internal length counter inside each adt_array object ("handle" on the pawn side), and did +1 every time you PushArray* and -1 if you remove something. GetArraySize should be O(1) then, as it's just a wrapper that just returns that number. (Basically, it shouldn't do an O(n) loop every time it's called.)

Anyway, the bottom line is... just because something is a killer in performance doesn't mean that your proposed solutions will run faster... because more often than not, they won't (especially if you're trying to beat C++ speed in pawn... lol ain't happening). Stick to the native and find other places in your plugin that are really sucking performance, as opposed to premature optimizing.

FYI: array.Length is the same as GetArraySize internally. The compiler inlines the call to GetArraySize() when you run your script through spcomp. You're not gaining any real-time performance by using what looks like a non-function call (-1 to methodmaps for this reason). Methodmaps are just syntax sugar... (as far as I understand) they don't exist at the smx level. It's still the same bytecode (more or less) as from SM 1.6 or older.

Last edited by Potato Uno; 07-24-2016 at 10:20.
Potato Uno is offline
Reply



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 23:58.


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