Gamemode efficiency
#1

Hello samp forums! My name is Max and i'd like to have some help with making my script faster.
Loading houses/businesses/factions/families/objects/gates was a really pain for me lately.
Heres my method to load & save.

Saving:
Код:
forward SaveHousesFunction();
public SaveHousesFunction()
{
        //Creates a loop, that goes through all of the files.
	for(new idx = 1; idx < sizeof(HouseInfo); idx++) //Loops through the houses.
	{
		if(!HouseInfo[idx][hLevel]) // If the house level is 0 this means it doesn't exist. (house must have level)
		{
			print("Houses saved successfully."); // If look broke we found all existed houses.
			break;//Breaks the loop if the price is 0(Meaning it doesn't exist)
		}
		SaveHouses(idx); // going to another function that saves houses by y_ini into specific house file.
	}
	return 1;
}
And the loading:
Код:
stock LoadHouses()
{
	new string[256];
	//Creates a loop, that goes through all of the files.
	for(new idx = 1; idx < sizeof(HouseInfo); idx++)
	{
		format(string, sizeof(string), hPATH, idx);//formats the file path, with the house ID
		INI_ParseFile(string, "loadhouse_%s", .bExtra = true, .extra = idx );
		HouseInfo[idx][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ], 0);
		if(!strcmp("The State", HouseInfo[idx][hOwner])) format(string, sizeof(string), "{00BC2E}[House]{FFFFFF}\n{00BC2E}Owner{FFFFFF}: %s\n{00BC2E}Type{FFFFFF}: %s\n{00BC2E}Status{FFFFFF}: For Sale\n{00BC2E}Price{FFFFFF}: $%d", HouseInfo[idx][hOwner], HT(idx), HouseInfo[idx][hPrice]);
		else format(string, sizeof(string), "{00BC2E}[House]{FFFFFF}\n{00BC2E}Owner{FFFFFF}: %s\n{00BC2E}Type{FFFFFF}: %s\n{00BC2E}Status{FFFFFF}: %s", HouseInfo[idx][hOwner], HT(idx), RHS(idx));
		HouseInfo[idx][hText] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]+0.3,  20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID);
		if(HouseInfo[idx][hLevel])
		{
			HouseInfo[idx][hOwned] = 1;
		}
	}
	return 1;
}
Is there any more efficent way you guys know to do this? If there is, it will help me with all the systems in the mod. all of them are saved and loaded the same way.

Thanks, Max.
Reply
#2

I have one,

Just one question before you continue, does all the systems that needs to be loaded and save exist? Like have you created every one of them? No?

Continue...

I do this with my code when I load

PHP код:
#define HPATH "Houses/%d.ini", or .file, or .txt etc

HouseDataPath(houseid)
{
  new 
pathname[10+3+1]; //15 coz 11 for the text ones including and 3 for the number one and a null
  
format(pathnamesizeof pathnameHPATHhouseid);
  return 
pathname;
}
for(new 
houseidhouse MAX_HOUSEShouseid++)
{
    if(
fexist(HouseDataPath(houseid))
   {
       
//Your code here
   
}

This way you won't be loading those that are not present and you won't be saving those that are non existent

Further more I do querystyle or something like that
PHP код:
QueryHouseData(houseidtype)
{
    switch(
type)
    {
         case 
CLEAR_HOUSEDATA:
         {
             
//code here
         
}
         case 
CREATE_HOUSEDATA:
         {
             
//code here
         
}
         case 
SAVE_HOUSEDATA:
         {
             
//code here
         
}
         case 
UPDATE_HOUSEDATA:
         {
             
//code here
         
}
         case 
LOAD_HOUSEDATA:
         {
        
INI_ParseFile(LoginPath(playerid), "LoadHouse_%s", .bExtra true, .extra houseid);
                
QueryHouseData(houseidBUFFER_HOUSEDATA);
    }
         case 
BUFFER_HOUSEDATA:
         {
             
//code here
         
}
     }
return 
1;

This way I can manage Data loading in just one go, and lesser functions that the script loads all the time,
Lastly I love enums
PHP код:
enum{
CLEAR_HOUSEDATACREATE_HOUSEDATASAVE_HOUSEDATAUPDATE_HOUSEDATALOAD_HOUSEDATA

Well if it helps then I'm glad I helped... If you think it won't help then, it's up to you.

Also to explain why save and update have different calls, it's because I use saving only when the gamemode closes, or a clutchsave needs to be done like when the gamemode is forced to restart to keep the data integrity intact
Update happens more frequently the only difference is that after the Update it Loads the data directly while save doesn't since save only happens when something bad happens.
Reply
#3

Interesting.. I'm going to test that out. thank you.
Reply
#4

File based systems are inefficient no matter how you look at it. Even though classic HDDs are being replaced in favor of SSDs, they're still the slowest part in the system. RAM is at least ten times faster to access.

You need to ask yourself whether it is necessary to rewrite the entire file. If nothing has changed, then why bother? I believe it's better to do updates on an "as needed" basis.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
File based systems are inefficient no matter how you look at it. Even though classic HDDs are being replaced in favor of SSDs, they're still the slowest part in the system. RAM is at least ten times faster to access.

You need to ask yourself whether it is necessary to rewrite the entire file. If nothing has changed, then why bother? I believe it's better to do updates on an "as needed" basis.
I do use this functions "as needed"...they're executed only under "OnGameModeExit" and manually by admin in cmd.

HOWEVER!

Is there a way to compile faster? it takes 1.34 minutes to compile a 82370 lines of code.
What to look for to reduce compilation time?
Tried to make looping through ONLY needed files & the amx size reduced from 21.5Mbytes to 8Mbytes. What else?
Reply
#6

The compiling is that long because pawncc (aka Pawn Compiler) has to compile your script, look for errors, and then giving the answer to you. It takes time, even if you had a Cluster of Computers (I think this is the name.. idk).
Reply
#7

Quote:
Originally Posted by 10MIN
Посмотреть сообщение
The compiling is that long because pawncc (aka Pawn Compiler) has to compile your script, look for errors, and then giving the answer to you. It takes time, even if you had a Cluster of Computers (I think this is the name.. idk).
Theres 0 errors, I need tips to lower script memory consumption. and no not the long string (arrays) tips, its very understoodable already.

Example to something I would love to understand is:
Using debugging level -d3 getting this compliation message:

Код:
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:          38056 bytes
Code size:          6014220 bytes
Data size:         22585444 bytes
Stack/heap size:      16384 bytes; estimated max. usage: unknown, due to recursion
Total requirements:28654104 bytes
Reply
#8

*bump*

I'm still really intrested in your thoughts! please continue..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)