View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-09-2023 , 06:11   Re: Question about native : get_players
Reply With Quote #6

I think that caching things like is_user_alive, is_use_connected, etc is pointless most of the time.

1. You are not gaining any tangible speed-up because calling those natives directly is already very cheap.
2. Correctly maintaining the cache may be non-trivial, error-prone, and require a lot of code.
3. It makes the whole plugin harder to understand and maintain.

I would only consider such micro-optimizations only if, in practice, the code is measurably too slow. That means I created it using a straightforward method, and while testing I noticed that it failed some performance metrics (like execution speed) and that the code is spending a lot of time calling natives like is_user_alive. Otherwise, even if the code is too slow, caching such native calls may not lead to any performance gain because they were not the reason for the slowdown.

Another potential pitfall to be aware of when thinking about caching native calls: keeping the cache updated should NOT be more expensive than just simply performing the native call.
__________________

Last edited by HamletEagle; 12-09-2023 at 06:14.
HamletEagle is offline