openmultiplayer / server-beta-old

open.mp server beta releases
142 stars 14 forks source link

[BEHAVIOR DIFFERENCE]: format/SendClientMessage take longer to process #109

Closed CiprianN23 closed 2 years ago

CiprianN23 commented 2 years ago

Description

I wrote a basic test for fun and decided to run on both sa-mp and open.mp and i noticed on open.mp it runs maybe 30 times slower

How to re-produce this behavior difference

#include <a_samp>
main() {}
public OnGameModeInit()
{
    new text[144];
    new tickCount = tickcount();

    for (new i = 0; i < 1000000; i++)
    {
        format(text, sizeof text, "Your id is %i", 0);
        SendClientMessage(0, -1, text);
    }

    printf("1.000.000 formated and sended messages: %i ms", tickcount() - tickCount);
}

Relevant log output

sa-mp

1.000.000 formated and sended messages: 157 ms

open.mp

[15:41:30] [Info] 1.000.000 formated and sended messages: 6855 ms

open.mp server version

open.mp public beta 5

Operating system or distribution

Windows 10 Pro 21H2 19044.1766

Contact information

Banditul#1549

Additional Information

Using an Intel i5-4460 3.4GHz

AmyrAhmady commented 2 years ago

With a little bit of testing, seems like we found the culprit The reason it is slower relies on two things:

  1. It is not a release build
  2. We throw exceptions when passed player id is invalid

That being said, on release build, with a connected player, open.mp is 2x faster than samp (you can try it yourself), I guess it's a fine tradeoff to improve a logical/reasonable condition and sacrifice (not really, no one does that in a real world example) the other. Therefore, the answer to your not-asked question is, no open.mp is not slower, it's your code that is not a good example for testing because that player doesn't exist in the first place and you sending 1 million messages to an invalid player (never happens in a real world situation)

CiprianN23 commented 2 years ago

Makes sense now. Thank you