[YSI] Inline + General
#1

Hello.
When I run my server, it took about 10 mins to load YSI. Local or hosted, it's the same thing. Why? How can I avoid this waiting time?
Код:
[15:06:52]  
[15:06:52]  ======================================= 
[15:06:52]  |                                     | 
[15:06:52]  |        YSI version 4.00.0001        | 
[15:06:52]  |        By Alex "******" Cole        | 
[15:06:52]  |                                     | 
[15:06:52]  ======================================= 
[15:06:52]  
[15:17:44] *** YSI Warning: y_malloc set up via "CallLocalFunction", memory corruption is a remote possibility
As you can see, I've YSI warning. I don't know how to solve it. I don't use y_hooks. The problem should come from
CallLocalFunction("OnGameModeExit", ""); ?

For inline part, I've 2 questions:
1. Are we "forced" to do the inline function (or whatever you call it) before the query like this example?
Quote:
Originally Posted by ******
PHP код:
inline FactionCreated()
    {
        
Iter_Add(Factionslot);
        
Faction.Meta[slot][@id] = DBID:cache_insert_id();
    
        new 
query[128 1];
        
mysql_format(dbhandlequerysizeof query"INSERT INTO faction_members(faction_id, player_id, rank) VALUES(%d, %d, %d)"_:Faction.Meta[slot][@id], _:Player.Auth[ownerid][@id], Y_RP_FACTION_MAX_RANK);
        
mysql_pquery(dbhandlequery);
    }
    new 
query[80 32 32 1];
    
mysql_format(dbhandlequerysizeof query"INSERT INTO factions(creator_id, owner_id, name, money) VALUES(%d, %d, '%e', %d)"_:Player.Auth[playerid][@id], _:Player.Auth[ownerid][@id], namebudget);
    
mysql_pquery_inline(dbhandlequeryusing inline FactionCreated); 
2. An inline function cannot be called by another function/cmd like any public and forwarded function?
Reply
#2

1 Yes. As far as I know inline works only on a structure like
PHP код:
ParentFunction()
{
    
inline ChildFunction()
    {
    }
    
FunctionToCallInline

2. No. Again, as far as I know inline functions are made to make your life easier. (Well, I have used inlines with Dialogs (y_dialog.inc) and Queries (MySQL R41)) If you need to call the function Externally you have 2 ways (as far as my brain can think): Make the inline to a public OR copy the inline to the function where it is required.
Reply
#3

11 minutes?! That's insane. Can you try for me compiling an empty project, only including <YSI\y_text>?

(and see how long does the loading take then)
Reply
#4

Quote:
Originally Posted by 10MIN
Посмотреть сообщение
1 Yes. As far as I know inline works only on a structure like
PHP код:
ParentFunction()
{
    
inline ChildFunction()
    {
    }
    
FunctionToCallInline

2. No. Again, as far as I know inline functions are made to make your life easier. (Well, I have used inlines with Dialogs (y_dialog.inc) and Queries (MySQL R41)) If you need to call the function Externally you have 2 ways (as far as my brain can think): Make the inline to a public OR copy the inline to the function where it is required.
Alright thanks.

Still have these 2 problems:
Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Hello.
When I run my server, it took about 10 mins to load YSI. Local or hosted, it's the same thing. Why? How can I avoid this waiting time?
Код:
[15:06:52]  
[15:06:52]  ======================================= 
[15:06:52]  |                                     | 
[15:06:52]  |        YSI version 4.00.0001        | 
[15:06:52]  |        By Alex "******" Cole        | 
[15:06:52]  |                                     | 
[15:06:52]  ======================================= 
[15:06:52]  
[15:17:44] *** YSI Warning: y_malloc set up via "CallLocalFunction", memory corruption is a remote possibility
As you can see, I've YSI warning. I don't know how to solve it. I don't use y_hooks. The problem should come from
CallLocalFunction("OnGameModeExit", ""); ?
EDIT:
Quote:
Originally Posted by Misiur
Посмотреть сообщение
11 minutes?! That's insane. Can you try for me compiling an empty project, only including <YSI\y_text>?

(and see how long does the loading take then)
Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7-R2, ©2005-2015 SA-MP Team

[16:12:47] filterscripts = ""  (string)
[16:12:47] 
[16:12:47] Server Plugins
[16:12:47] --------------
[16:12:47]  Loading plugin: sscanf
[16:12:47] 

[16:12:47]  ===============================

[16:12:47]       sscanf plugin loaded.     

[16:12:47]          Version:  2.8.2        

[16:12:47]    © 2012 Alex "******" Cole  

[16:12:47]  ===============================

[16:12:47]   Loaded.
[16:12:47]  Loading plugin: mysql
[16:12:47]  >> plugin.mysql: R41-4 successfully loaded.
[16:12:47]   Loaded.
[16:12:47]  Loaded 2 plugins.

[16:12:47] 
[16:12:47] Filterscripts
[16:12:47] ---------------
[16:12:47]   Loaded 0 filterscripts.

[16:12:47]  
[16:12:47]  
[16:12:47]  
[16:12:47]  ======================================= 
[16:12:47]  |                                     | 
[16:12:47]  |        YSI version 4.00.0001        | 
[16:12:47]  |        By Alex "******" Cole        | 
[16:12:47]  |                                     | 
[16:12:47]  ======================================= 
[16:12:47]  
[16:12:49] *** YSI Error: No languages found - Did you add "Langs_AddLanguage" to the script init (NOT "main")?
[16:12:49] main()
[16:12:49] Number of vehicle models: 0
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
I have never seen it take that long, even with full debugging enabled, which hugely reduces load times. What machine are you running on, and how big is your compiled code size?
Local: w8.1 - amx file : 8 041 ko (not optimised)
Basically, I'm optimising this gamemode. The first step is to update MySQL (R5 to R40)
Compilation
Код:
Header size:          19320 bytes
Code size:          9205372 bytes
Data size:          9758740 bytes
Stack/heap size:   16827216 bytes; estimated max. usage=9898 cells (39592 bytes)
Total requirements:35810648 bytes
Quote:
Originally Posted by ******
Посмотреть сообщение
No one mentioned y_hooks there... Also why are you manually calling `OnGameModeInit` like that? That's bound to cause issues!
OnGameModeExit is called like that when connect to MySQL failed

Quote:
Originally Posted by ******
Посмотреть сообщение
That's not really a question...
Lol, I know it was a stupid question but I'm curious how it works. A function inside a callback/another function/etc.. I've never saw that before
Reply
#6

8MB is nothing, so that's not the reason. Calling exit like that is fine, not a cause for the problem. Inline function creates "real" function in memory when it's first called (IIRC), then it's 0-overhead call.(well, maybe except for pushing local variables). Can you add "#define _DEBUG 7" at the top of your gamemode, and paste the server log output somewhere? It might be huge if something is wrong (and it is, 11 minutes is not a normal state of things)
Reply
#7

I don't know if it can be usefull but I post the list of include used in the gamemode:
Код:
#include <a_samp>
// #include <a_mysql>
#include <a_http>
#include <fixes>
#include <crashdetect>
#include <streamer>
#include <sscanf2>
#include <mSelection>

#define _DEBUG 7
#define DYNAMIC_MEMORY 12500
#include <YSI\YSI\y_va>
#include <YSI\YSI\y_inline>
#include <YSF>
// #include <YSI\YSI\y_iterate> // not yet
#include <a_mysql_yinline>

#include <geolocation>
And what you asked:
Код:
[18:56:56]  
[18:56:56]  ======================================= 
[18:56:56]  |                                     | 
[18:56:56]  |        YSI version 4.00.0001        | 
[18:56:56]  |        By Alex "******" Cole        | 
[18:56:56]  |                                     | 
[18:56:56]  ======================================= 
[18:56:56]  
[18:56:57] YVA2_FoundPush: 4
[18:56:57] YVA2_FoundPush: 4
[18:56:57] YVA2_FoundPush: 88
[18:56:57] YVA2_FoundPush: 4
[18:56:57] YVA2_FoundPush: 4
[18:56:57] YVA2_FoundPush: 4
[18:57:05] YVA2_FoundPush: 1156
[19:07:47] Malloc_OnScriptInit called
[19:07:47] AMX_Read called: -9218732 -20
[19:07:47] AMX_RawRead called: -9218732
[19:07:47] AMX_Read called: -9213180 -20
[19:07:47] AMX_RawRead called: -9213180
[19:07:47] AMX_Write called: -9119108, 134
[19:07:47] AMX_Write called: -9119104, 134
[19:07:47] AMX_Write called: -9058168, 134
[19:07:47] AMX_Write called: -9058164, 134
[19:07:47] AMX_Write called: -9058036, 134
[19:07:47] AMX_Write called: -9058032, 134
[19:07:47] AMX_Write called: -9057080, 134
[19:07:47] AMX_Write called: -9057076, 134
[19:07:47] AMX_Write called: -9056752, 134
[19:07:47] AMX_Write called: -9056748, 134
[19:07:47] AMX_Write called: -9056572, 134
[19:07:47] AMX_Write called: -9056568, 134
[19:07:47] AMX_Write called: -9056484, 134
[19:07:47] AMX_Write called: -9056480, 134
[19:07:47] AMX_Write called: -9056304, 134
[19:07:47] AMX_Write called: -9056300, 134
[19:07:47] AMX_Write called: -9056120, 134
[19:07:47] AMX_Write called: -9056116, 134
[19:07:47] AMX_Write called: -9056024, 134
[19:07:47] AMX_Write called: -9056020, 134
[19:07:47] AMX_Write called: -9055780, 134
[19:07:47] AMX_Write called: -9055776, 134
[19:07:47] AMX_Write called: -9055704, 134
[19:07:47] AMX_Write called: -9055700, 134
[19:07:47] AMX_Write called: -9055616, 134
[19:07:47] AMX_Write called: -9055612, 134
[19:07:47] AMX_Write called: -9055376, 134
[19:07:47] AMX_Write called: -9055372, 134
[19:07:47] AMX_Write called: -9055084, 134
[19:07:47] AMX_Write called: -9055080, 134
[19:07:47] AMX_Write called: -9054900, 134
[19:07:47] AMX_Write called: -9054896, 134
[19:07:47] AMX_Write called: -9054696, 134
[19:07:47] AMX_Write called: -9054692, 134
[19:07:47] AMX_Write called: -9054592, 134
[19:07:47] AMX_Write called: -9054588, 134
[19:07:47] AMX_Write called: -9054516, 134
[19:07:47] AMX_Write called: -9054512, 134
[19:07:47] AMX_Write called: -9054348, 134
[19:07:47] AMX_Write called: -9054344, 134
[19:07:47] AMX_Write called: -9054280, 134
[19:07:47] AMX_Write called: -9054276, 134
[19:07:47] AMX_Write called: -9054180, 134
[19:07:47] AMX_Write called: -9054176, 134
[19:07:47] AMX_Write called: -9054132, 134
[19:07:47] AMX_Write called: -9054128, 134
[19:07:47] AMX_Write called: -9054056, 134
[19:07:47] AMX_Write called: -9054052, 134
[19:07:47] AMX_Write called: -9053960, 134
[19:07:47] AMX_Write called: -9053956, 134
[19:07:47] AMX_Write called: -9053808, 134
[19:07:47] AMX_Write called: -9053804, 134
[19:07:47] AMX_Write called: -9053704, 134
[19:07:47] AMX_Write called: -9053700, 134
[19:07:47] AMX_Write called: -9053632, 134
[19:07:47] AMX_Write called: -9053628, 134
[19:07:47] AMX_Write called: -9053528, 134
[19:07:47] AMX_Write called: -9053524, 134
[19:07:47] AMX_Write called: -8909128, 134
[19:07:47] AMX_Write called: -8909124, 134
[19:07:47] AMX_Write called: -8908988, 134
[19:07:47] AMX_Write called: -8908984, 134
[19:07:47] AMX_Write called: -2309900, 134
[19:07:47] AMX_Write called: -2309896, 134
[19:07:47] AMX_Write called: -2308744, 134
[19:07:47] AMX_Write called: -2308740, 134
[19:07:47] Malloc_TrySetup called
[19:07:47] *** YSI Warning: y_malloc set up via "CallLocalFunction", memory corruption is a remote possibility
[19:07:47] Malloc_OnScriptInit: 9763716 16777216 9763716
[19:07:47] Malloc_OnScriptInit: AMX_HEADER_HEA = 9763716, YSI_gMallocMemory = 395020, YSI_g_sHeapStart = 2342174
[19:07:47] Malloc_OnScriptInit: YSI_gMallocMemory + 4 * YSI_g_sHeapStart = 9763716
[19:08:16] [boot] OnGameModeInit launched !
Reply
#8

UP ! The problem still there
Reply
#9

Short of running a exe debugger to see what's happening during that time, I don't see a solution as of now.

How to debug this? Well, standard divide and conquer. Comment out parts of your code (main and OnGameModeInit in this case) until you see improvement, then pinpoint the cause
Reply
#10

Alright. I commented both and nothing change. main() was already empty (only some prints) and OnGameModeInit() contain only MySQL connexion
Reply
#11

More commenting then. Comment out everything, includes too, then uncomment step by step until you get the problem again. If empty gamemode still causes this, it'll be a really weird thing.
Reply
#12

The problem come from OnPlayerCommandText. All the commands are right there. I removed it and it took 20 seconds to load YSI.
Reply
#13

Alright, finally some progress. Now comment out parts of OPCT until you find the offender
Reply
#14

Quote:
Originally Posted by Misiur
View Post
Alright, finally some progress. Now comment out parts of OPCT until you find the offender
Isn't enough? I mean, I think more the code is bigger (not in number of line), more YSI take time to load
Reply
#15

But not 11 minutes! One of the humongous gamemodes I worked on was 200k lines and took like 30 seconds to load
Reply
#16

Quote:
Originally Posted by Misiur
View Post
But not 11 minutes! One of the humongous gamemodes I worked on was 200k lines and took like 30 seconds to load
It was optimized?
3/4 of the commands right there need to be optimized. 47k lines. Half of the game is only commands. I think to optimize it first and see after this if something changed, don't you think?
Reply
#17

Quote:
Originally Posted by Y_Less
View Post
Commands will make no difference to startup - they aren't run then. And you can't optimise without profiling first, how will you know what is slow?
I was talking about basic optimisations like use switch + case instead of 50 else if conditions, use sscanf when needed it, etc..
But, I never though I can use profiler for optimization. Probably because I don't know how to use it.
Anyway, there is the summary (the file you get after profiling a gm/fs) without OnPlayerCommandText because the server freeze (or doesn't load anymore) during loading YSI : https://www.mediafire.com/file/l35ja...-profiler.html

NB: Thanks both of you for your precious help
Reply
#18

Quote:
Originally Posted by Y_Less
View Post
Edit: Nope...

Edit 2:

57% of that execution is spent in this function:

https://github.com/Zeex/amx_assembly....inc#L243-L277

I can see why it would be so slow - it runs all that code for almost every cell in your code, multiple times! I mean the code was never designed for speed, since it is only run once at startup. I've never been too concerned with startup times, only live execution times, so if there is ever a way to speed up execution at the cost of startup, I will always take it (unless the code is very complex). In this case, however, I might have to rethink. Expecially code that is not too well written - large functions with high cyclomatic complexity will not treat that function well.
Alright. Well, nothing I can do to reduce the time it take for load YSI? I've to wait a new version of your code ? Without a new version, wait 10 mins is a problem for tests server, it's not for the production server.
Reply
#19

Quote:
Originally Posted by Y_Less
View Post
Unfortunately, that's currently the gist of it, yes. I am looking in to making that function faster, but it needs a serious think. Maybe I should do something like this (which I considered last time, but believed was too much effort for the payoff): https://en.wikipedia.org/wiki/Knuth%...ratt_algorithm

Edit: I started looking at the jump targets code, trying to speed it up with a binary search or something else. Then I realised it was TOTALLY unneeded! Even without it, the code will still report the correct stack in 99.999% of cases, and the other cases would be ambiguous even in the server VM anyway, so may as well go with the other version of that ambiguity and report it semi accurate always.

So I just deleted all the code dealing with jump targets entirely!
Should I do the same thing?
Reply
#20

10 minuts to 10/20 seconds. What a very nice job you did there.
The last profiling I made without your update, it was without commands because the server freeze or crash when it load YSI.
Now I can and I have to wait only 10/20 seconds. Thanks a lot. Profiling file (the new one): http://www.mediafire.com/file/u3y7f9...e-profile.html
---------------------
I still have a warning which I don't know how to solve:
[10:27:55] *** YSI Warning: y_malloc set up via "CallLocalFunction", memory corruption is a remote possibility
What "memory corruption" means? What should I do?
---------------------
Finally, I have one query inline which doesn't work. It is never called. Other inline callback are called.
PHP Code:
        mysql_format(databasequerysizeof(query), "SELECT * FROM `gtrp_factions_ranks` WHERE `FactionSQLID` = %i ORDER BY `gtrp_factions_ranks`.`Rank` ASC"j);
        
inline OnRanksLoading(factionID)
        {
            
J::D("Inside inline: %s"FactionInfo[j][fName], j);
            new 
temporary,
                
num_ranks cache_num_rows();
            if(!
num_ranks)
            {
                
CreateRanksForFactions(factionID);
                return 
J::D("No ranks loaded for %s. They have been created."GetFactionName(factionID));
            }
            for(new 
k!= num_ranksk++)
            {
                
cache_get_value_int(k"Rank"temporary);
                
cache_get_value(k"RankName"f_RankName[factionID][temporary], MAX_FAC_RANK_NAME);
                
J::D("Rank %i (%s) loaded for %s"temporaryf_RankName[factionID][temporary], GetFactionName(factionID));
            }
        }
        
J::D("Faction \"%s\" (id: %i) loaded | Loading ranks 2.0"FactionInfo[j][fName], j);
        
mysql_pquery_inline(databasequeryusing inline OnRanksLoading"i"j); 
No errors, no warnings, nothing in the logs
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)