<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://opensimulator.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://opensimulator.org/index.php?action=history&amp;feed=atom&amp;title=Scripts_Performance</id>
		<title>Scripts Performance - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://opensimulator.org/index.php?action=history&amp;feed=atom&amp;title=Scripts_Performance"/>
		<link rel="alternate" type="text/html" href="http://opensimulator.org/index.php?title=Scripts_Performance&amp;action=history"/>
		<updated>2026-04-04T21:49:30Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.9</generator>

	<entry>
		<id>http://opensimulator.org/index.php?title=Scripts_Performance&amp;diff=41162&amp;oldid=prev</id>
		<title>Orenh: Created page with &quot;== Measuring Scripts Performance ==  === For Users ===  Users can check their scripts' performance in two places in the viewer: # The '''Statistics''' panel - the &quot;Script Time...&quot;</title>
		<link rel="alternate" type="text/html" href="http://opensimulator.org/index.php?title=Scripts_Performance&amp;diff=41162&amp;oldid=prev"/>
				<updated>2015-08-11T09:48:19Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Measuring Scripts Performance ==  === For Users ===  Users can check their scripts&amp;#039; performance in two places in the viewer: # The &amp;#039;&amp;#039;&amp;#039;Statistics&amp;#039;&amp;#039;&amp;#039; panel - the &amp;quot;Script Time...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Measuring Scripts Performance ==&lt;br /&gt;
&lt;br /&gt;
=== For Users ===&lt;br /&gt;
&lt;br /&gt;
Users can check their scripts' performance in two places in the viewer:&lt;br /&gt;
# The '''Statistics''' panel - the &amp;quot;Script Time&amp;quot; field shows the total execution time for all the scripts in the region in the last frame&lt;br /&gt;
# The '''Top Scripts''' window - shows the total execution time in the last 30 seconds of the slowest scripts in the region&lt;br /&gt;
&lt;br /&gt;
=== For Developers ===&lt;br /&gt;
&lt;br /&gt;
Both of these statistics are calculated by measuring the execution time of each Script Instance.&lt;br /&gt;
* '''ScriptInstance.executionTimer''' is a Stopwatch that's used whenever the script is being processed in the scripting engine.&lt;br /&gt;
* This timer is automatically stopped when the script is sleeping, and restarted afterwards. See '''OSSL_Api.ScriptSleep()''' and '''LSL_Api.Sleep()'''. That's done because scripts don't use any CPU power while they're sleeping.&lt;br /&gt;
* Each Scene adds up all of its scripts' execution times each frame. See '''Scene.m_scriptExecutionTime'''. This is what's shown in the &amp;quot;Statistics&amp;quot; panel.&lt;br /&gt;
* Each ScriptInstance uses a sliding window to keep track of its execution time in the last 30 seconds. See '''ScriptInstance.ExecutionTime''', which is an instance of the '''MetricsCollectorTime''' class. This is what's shown in the &amp;quot;Top Scripts&amp;quot; window.&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
We use the Stopwatch class to calculate the script execution times. This is a high-resolution timer, which is important because many script executions take less than 1ms, so a lower-resolution timer would think that the script didn't take any time at all.&lt;br /&gt;
&lt;br /&gt;
The script time is &amp;quot;gross time&amp;quot;, i.e. including the time the scripting engine used before and after the actual script execution. That's because this time should be attributed to the script's execution time, as it takes CPU power. For example, a script that fires thousands of events per second causes the scripting engine to do a lot of setup and teardown work that isn't part of the script's actual work, but it does slow down the simulator.&lt;br /&gt;
&lt;br /&gt;
When a script is Stopped, we don't reset its ExecutionTime. This is done to allow the user to see runaway scripts, i.e. scripts that have executed for so long that they were forcibly aborted. When a script is forcibly aborted, it's Stopped. If we had reset the ExecutionTime when scripts are stopped then paradoxically, runaway script wouldn't have shown up in the &amp;quot;Top Scripts&amp;quot; dialog, even though they're the top CPU hogs among all the scripts.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Top Scripts&amp;quot; window shows the script's execution time in the last 30 seconds. This value needs to be short, so that when users modify a script to make it faster they can get quick feedback.&lt;br /&gt;
&lt;br /&gt;
=== Possible Future Improvements ===&lt;br /&gt;
&lt;br /&gt;
Currently, when scripts are sleeping this is done by making the script thread sleep. Although this doesn't use the CPU, it does lock up one of the limited number of script threads. A better implementation would be to release the thread during sleeps. However, since we already use quite a lot of threads, this doesn't seem like a high priority.&lt;br /&gt;
&lt;br /&gt;
It would be nice if we could measure a script's memory usage: both total memory used, and memory thrashing which leads to garbage-collection time. E.g., a script that does a lot of work with lists is probably constantly creating and discarding lists, which is inefficient.&lt;/div&gt;</summary>
		<author><name>Orenh</name></author>	</entry>

	</feed>