These are chat archives for ikkentim/SampSharp

3rd
Jul 2015
Tim Potze
@ikkentim
Jul 03 2015 13:57
Merged it :clap:
Tim Potze
@ikkentim
Jul 03 2015 21:49
I'm working on a new way of calling native functions. It's a structure called NativeFunction. When you initialise this structure, you pass on the name of the native it represents and the format of the arguments, e.g. new NativeFunction("GetGravity"), new NativeFunction("CreateVehicle", "dffffdddb") o new NativeFunction("GetNetworkStats", "Sd", 1).
Florian van Dillen
@fvandillen
Jul 03 2015 21:50
Cool!
Tim Potze
@ikkentim
Jul 03 2015 21:50
In before, calling SA-MP (vanilla) natives, you simply call Native.NativeName(), but for other natives, from plugins, you had to use Native.CallNative.
Florian van Dillen
@fvandillen
Jul 03 2015 21:51
Dont forget to go out and grab some beers: its weekend;)
Tim Potze
@ikkentim
Jul 03 2015 21:51
the NativeFunction structure is significantly faster than Native.CallNative, but it is slower than Native.NativeName() (for vanilla natives).
I'm considering removing the Native.NativeName() functions.
Marco Acierno
@marcoacierno
Jul 03 2015 21:52
Seems interessing and could improve the code inside the Native.cs file
Seems interesting*
Tim Potze
@ikkentim
Jul 03 2015 21:52
and reimplementing these on the framework side ofc...
Here are the speed comparisons:

Test with GetNetworkStats (100000x)
NativeFunction: 00:00:02.1300141
Direct call: 00:00:01.9585855
CallNative: 00:00:02.6525977

Test with GetGravity (100000x)
NativeFunction: 00:00:00.0423545
Direct call: 00:00:00.0141799
CallNative: 00:00:00.1052560

Test with Create/DestroyVehicle (100000x)
NativeFunction: 00:00:00.6445752
Direct call: 00:00:00.2432979
CallNative: 00:00:01.9774830

As you can see NativeFunction (the new structure) is much faster than CallNative, and only slightly slower than a direct call.
Removing the direct calls has some pros and some cons
pros: +It cleans up the plugin code massively +When fixing a bug native calls, I only need to fix it in one place +If SA-MP gets updated, we only need to update the framework, not the plugin
cons: -It's slower.
Now is my question, do the pros outweigh the cons?
@fvandillen I've had weekend for 4 weeks now.
Marco Acierno
@marcoacierno
Jul 03 2015 22:04
I don't know if there differences are so noticeable in the "real world" usage.
Tim Potze
@ikkentim
Jul 03 2015 22:04
I agree.
Marco Acierno
@marcoacierno
Jul 03 2015 22:06
The pros to have a plugin/framework that can be updated to newer samp version instantly without wait 2 weeks or more would be much more appreciated
Tim Potze
@ikkentim
Jul 03 2015 22:08
In the test with GetGravity it means a 44% slowdown... But that's only 0.4 ms difference per 100 calls, only 0.004 ms difference per call.
Marco Acierno
@marcoacierno
Jul 03 2015 22:08
And removing the need to fix the same bug in two places, is a big plus. We reduce the possibility to introduce new bugs
Tim Potze
@ikkentim
Jul 03 2015 22:08
I'll go ahead and go it then :)
Marco Acierno
@marcoacierno
Jul 03 2015 22:09
Well, gamemode that reach that point of 1000 calls have some other serious problems, I think
gamemodes*
Tim Potze
@ikkentim
Jul 03 2015 22:09
yea :smile:
Marco Acierno
@marcoacierno
Jul 03 2015 22:09
There could be speed critical gamemodes, but..
Tim Potze
@ikkentim
Jul 03 2015 22:11
I wouldn't be surprised if these calls are still 100 times faster than calls in pawn
I've never really done a good speed comparison with pawn or other available languages and TBH I have no idea how to test speed reliably in pawn
Marco Acierno
@marcoacierno
Jul 03 2015 22:17
I don't remember, but for simple and fast tests a simple for and a (msStart-msEnd) can give you something. Then you can try to test disable optimization etc.
But I think there are some libraries that do it better. (maybe one of Y_Less)
Marco Acierno
@marcoacierno
Jul 03 2015 22:45
funny, I love Stackoverflow/Programmers/Codereview sites. They are amazing