Maniascript slows down fps when joining to server 150 player

Moderator: NADEO

Locked
reaby
Posts: 956
Joined: 29 Dec 2010, 23:26
Location: Eastern Finland
Contact:

Maniascript slows down fps when joining to server 150 player

Post by reaby »

So, everything is so much funnier with more players on server,
with 150 fake players things gets veeery interesting...

when player joins to server, the fps drops to around 10, with our eXpansion pluginspack maniascripts, i have to say i can't pinpoint the exact reason or script what does it.... if map changes or manialive is restarted when all the players are on the server fps is 100, but if i disconnect and reconnect, 10fps :D

I asked magnetik to confirm this bug.. and he said to post this screenshot to forums:
http://i.imgur.com/hRIsXXF.jpg

hopefully this gets sorted out, testing and finding the bug should be fairly easy.... just eXpansion with manialive @ 150 or more players, join server when everything is running :)
reaby
Posts: 956
Joined: 29 Dec 2010, 23:26
Location: Eastern Finland
Contact:

Re: Maniascript slows down fps when joining to server 150 pl

Post by reaby »

User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: Maniascript slows down fps when joining to server 150 pl

Post by Eole »

The slow down seems indeed to be caused by one of the manialink. Did you try to have only one manialink active at a time to see if the problem comes from a specific manialink or if it's a combined effect from all the manialinks together?
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
oliverde8
Posts: 1286
Joined: 16 Jun 2010, 07:33
Location: in a Blue Box

Re: Maniascript slows down fps when joining to server 150 pl

Post by oliverde8 »

Hi,
It took us some time to pinpoint the problem. We believe this bit of codes creates the slow downs :

Code: Select all

    eXp_lastWidgetCheck = Now;
    if (!exp_widgetVisible.existskey(version) ) {
	exp_widgetVisible[version] = Boolean[Text];
     }

     if (!exp_widgetVisible[version].existskey(id)) {
	    exp_widgetVisible[version][id] = True;
    }

    if (!exp_widgetLayers[version].existskey(id)) {
	exp_widgetLayers[version][id] = "normal";
    }

    if (exp_widgetVisible[version][id] == True && exp_widgetLayers[version][id] == activeLayer && exp_widgetCurrentVisible != exp_widgetVisible[version][id]) {
	Window.Show();
	exp_widgetVisibilityChanged = True;
	exp_widgetCurrentVisible = True;
    } else if(exp_widgetCurrentVisible != exp_widgetVisible[version][id] || exp_widgetLayers[version][id] != activeLayer) {
	Window.Hide();
	exp_widgetCurrentVisible = False;
    }


    if (exp_enableHudMove == True) {
	    quad.Show();
    }else {
	    quad.Hide();
    }
    exp_widgetLayersBuffered = exp_widgetLayers[version][id];
    exp_widgetVisibleBuffered = exp_widgetVisible[version][id];
It is when we use persistent variables that it slow downs. Removing this part of the code will fix fps of the new player that joins the server and also impove the overall fps.
Removing the Window.show and all the things in the if's has no effect.

We tried to do this also :

Code: Select all

if((Now - eXp_lastWidgetCheck) > 500){
    eXp_lastWidgetCheck = Now;
    if (!exp_widgetVisible.existskey(version) ) {
	exp_widgetVisible[version] = Boolean[Text];
     }

     if (!exp_widgetVisible[version].existskey(id)) {
	    exp_widgetVisible[version][id] = True;
    }

    if (!exp_widgetLayers[version].existskey(id)) {
	exp_widgetLayers[version][id] = "normal";
    }

    if (exp_widgetVisible[version][id] == True && exp_widgetLayers[version][id] == activeLayer && exp_widgetCurrentVisible != exp_widgetVisible[version][id]) {
	Window.Show();
	exp_widgetVisibilityChanged = True;
	exp_widgetCurrentVisible = True;
    } else if(exp_widgetCurrentVisible != exp_widgetVisible[version][id] || exp_widgetLayers[version][id] != activeLayer) {
	Window.Hide();
	exp_widgetCurrentVisible = False;
    }


    if (exp_enableHudMove == True) {
	    quad.Show();
    }else {
	    quad.Hide();
    }
    exp_widgetLayersBuffered = exp_widgetLayers[version][id];
    exp_widgetVisibleBuffered = exp_widgetVisible[version][id];
}
This improves a lot overall FPS
but when you join the server during the first map you get lags every 500ms which is nearly worse then the overall fps dropdown.

Some numbers :D

Code: Select all

+------------------------------+-------------+-------------------------------+
|                              | On Join FPS | Global FPS(After Map Changed) |
+------------------------------+-------------+-------------------------------+
| First Code                   |      20     |             45-50             |
+------------------------------+-------------+-------------------------------+
| Second Code                  |      30     |             55-60             |
+------------------------------+-------------+-------------------------------+
| Removed Persistant variables |      50     |               60              |
+------------------------------+-------------+-------------------------------+
So we were able to fix our global FPS drain but when a player newly joins the server he can't play, he needs to wait a map skip for his FPS to stabilize.
Starting the server controller when players are on the server doesn't cause this slow down.

Thanks, if you need anything else :)

Edit : This code is repeated over nearly all our widgets soo 20 times.
Edit2 : The problem might be that on join all these widgets are synched and goes in the if of the code in the same frame? We will try to see if dong something where the waiting time is different for each widget on first loop improves anything
Edit3 : ^^I tried to add a 10ms gap between all the windows of the same player at first loop to see it it changed anything it sadly didin't.
Image
Developper for The next generation, Clean and Powerfull controller eXpansion for your SM & TM server . Working on eXpansion² with full MP4 support and many other awesome features...
User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: Maniascript slows down fps when joining to server 150 pl

Post by Eole »

Thanks for the detailed report.

So if I understand correctly some of your variables are declared as persistent (exp_widgetVisible and exp_widgetLayers?).
Does these two arrays contain a lot of values? If they are declared as persistent variables do you empty them at some point? Maybe the arrays got bigger and bigger during your tests and as they are persistent, if they are never emptied the script will start to consume more and more resources. If you log the content of these arrays do you see something abnormal?

The "if((Now - eXp_lastWidgetCheck) > 500)" part is always a good idea if the UI doesn't need to be updated at each frame and can save a lot of resources too, especially when there's a lot of Manialink script running.
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
oliverde8
Posts: 1286
Joined: 16 Jun 2010, 07:33
Location: in a Blue Box

Re: Maniascript slows down fps when joining to server 150 pl

Post by oliverde8 »

Well yes forgoth to mention it which of the vars are persistent :
exp_widgetVisible
exp_widgetLayers
are persistent, on the first dimension we should have maximum 2 values(tables) one for the old version of eXpansion one for the new.
The next layer just contains 30 values max. It total both variables contains 120 value. Which isn't a lot.

Version is a constant that changes only when we change the default layer positions we have changed it only once until now. id is the name of the widget that is hard coded in each widget. So there array size are constant.

What we are surprised is that it is the player count on the server that affects the performance of this code. If there is only 20 players on the server there is no problem. When there is more then 50 problems starts.
And as said earlier the problem exist only on first joint, once the map changes the fps drop with the maniascript running becomes negligible.

Thanks for your time :D
Image
Developper for The next generation, Clean and Powerfull controller eXpansion for your SM & TM server . Working on eXpansion² with full MP4 support and many other awesome features...
User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: Maniascript slows down fps when joining to server 150 pl

Post by Eole »

We don't have a solution for your problem yet but I think you might get some FPS back with some little optimizations.

The first easy thing you can check is if a log() is spammed. Calling the log() function at each frame on the client side can heavily reduce the FPS of the player.

Accessing a persistent variable seems indeed slightly more resource consuming. One way to optimize this would be to create some kind of Load() and Save() functions. The script would use variable declared for UI most of the time and use the Load() and Save() functions at initialization or when an update occurs to save the UI variable into the persistent variable.

A small example :

Code: Select all

<script><!--
#Include "MathLib" as ML

Void Save() {
	declare persistent MyPersistentVariable = 0;
	declare MyVariable for UI = 0;
	MyPersistentVariable = MyVariable;
}

Void Load() {
	declare persistent MyPersistentVariable = 0;
	declare MyVariable for UI = 0;
	MyVariable = MyPersistentVariable;
}

main() {
	declare MyVariable for UI = 0;

	Load();

	while (True) {
		yield;

		// Use the "declare for UI" variable in your code
		for (I, 1, 1000) {
			if (MyVariable == ML::Rand(MyVariable-10000, MyVariable+10000)) {
				MyVariable += 1;
				Save();
			}
		}
	}
}
--></script>
Instead of accessing the persistent variable 1000 times at each frame to test it, I do it only when a change occur. The rest of the time I use the declared for UI variable.

Another thing to know is that a variable declared for UI is shared between all the Manialink scripts running on the client. It can be messy at times but also useful because one manialink can drive and communicate with other sub-manialink.
By example you could have a Manialink without any UI but just a script that catches events, allows the player to move the widgets and saves their positions in a variable declared for UI. Then each widget manialink has a small script watching if its position in the variable declared for UI has changed and updates the widget position accordingly. This way instead of executing a big update n times on n manialink, I do it one time on the main manialink and after each sub-manialink only do a small update instead of the big one.
I used something in this spirit to create a lib allowing the player to move all the UI elements at will just like your eXpansion plugin. BUT (yes a big but ^^) depending on your coding philosophy and how your code is organized it can be more harmful than helpful. So it's a technique to use with care to avoid any bad surprises.

Last but not least, until now ManiaScript didn't really like arrays and that was one of the more common source of performance issues. But in the next version of ManiaPlanet the script engine was drastically optimized which can significantly improve performance in some cases.
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
oliverde8
Posts: 1286
Joined: 16 Jun 2010, 07:33
Location: in a Blue Box

Re: Maniascript slows down fps when joining to server 150 pl

Post by oliverde8 »

Hi thanks a lot Eole, it has certainly be constructive and there is a lot ideas upthere :clap: . It needs some time of reflection before I can create any ideas.

The only true problem comes from the persistent variables that are shared through the multiple manialinks. We were able to optimize the windows positions because we now in that manialive when they need to change so the check isn't done with a persistent variable.

I was thinking adding a single new persistent variable that says make a check. I check every 500ms only that persistent variable and not all of them. Simple Boolean variable that stays true for 1000ms only then back to false. This wy every 500ms I only check one variable.
I will try that.

Thanks a lot for your time. :thumbsup:
Image
Developper for The next generation, Clean and Powerfull controller eXpansion for your SM & TM server . Working on eXpansion² with full MP4 support and many other awesome features...
oliverde8
Posts: 1286
Joined: 16 Jun 2010, 07:33
Location: in a Blue Box

Re: Maniascript slows down fps when joining to server 150 pl

Post by oliverde8 »

Hi thanks again Eole,
replacing some persistences with for Ui and some tables with for Player we were able to optimize quite a bit.

We still have slightly less FPS on join then after first map but the difference is insignifiant.

Thanks for all you tips.
Image
Developper for The next generation, Clean and Powerfull controller eXpansion for your SM & TM server . Working on eXpansion² with full MP4 support and many other awesome features...
User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: Maniascript slows down fps when joining to server 150 pl

Post by Eole »

Nice to hear. The improvements on the ManiaScript engine will probably improve your performances a bit more in ManiaPlanet 3. :)
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
Locked

Return to “Maniaplanet Reports”

Who is online

Users browsing this forum: No registered users and 0 guests