{"id":2116,"date":"2015-08-05T15:04:01","date_gmt":"2015-08-05T15:04:01","guid":{"rendered":"https:\/\/www.kitely.com\/virtual-world-news\/?p=2116"},"modified":"2015-08-05T15:04:45","modified_gmt":"2015-08-05T15:04:45","slug":"new-tools-for-fixing-slow-scripts","status":"publish","type":"post","link":"https:\/\/www.kitely.com\/virtual-world-news\/2015\/08\/05\/new-tools-for-fixing-slow-scripts\/","title":{"rendered":"New Tools for Fixing Slow Scripts"},"content":{"rendered":"<p>We updated our system today with several\u00a0new features. First, we vastly improved the ability to find\u00a0and fix slow scripts; this has a big impact on world performance. We&#8217;ll contribute this feature to the OpenSim project soon. Next, we continued to\u00a0improve support for items that were obtained in\u00a0other grids. Finally, we added a few features that improve usability.<\/p>\n<p><strong>How to Fix Slow Worlds<\/strong><\/p>\n<p>Don&#8217;t you hate it when you visit a slow world, where every step you take causes rubber-banding,\u00a0and chatting is slow and jerky? When worlds are slow, that&#8217;s almost always caused by either\u00a0slow physics or slow scripts. World Managers are responsible for making sure that their worlds are fast and provide a good experience to visitors. But how can\u00a0you, the world manager, know\u00a0if your world is fast or slow?<\/p>\n<p>The first thing you need to check is the\u00a0<strong>Statistics<\/strong> panel. You can open this\u00a0panel by pressing\u00a0<strong>Ctrl+Shift+1<\/strong> in the viewer. The panel shows many statistics, but\u00a0the two most important statistics are the\u00a0<strong>Physics Time<\/strong> and\u00a0<strong>Script Time<\/strong>. If they show high values then\u00a0that tells you that you have a problem that needs to be fixed.<\/p>\n<p><a href=\"https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/statistics.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2121\" src=\"https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/statistics.png\" alt=\"Statistics\" width=\"259\" height=\"650\" srcset=\"https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/statistics.png 259w, https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/statistics-120x300.png 120w\" sizes=\"auto, (max-width: 259px) 100vw, 259px\" \/><\/a><\/p>\n<p>This screenshot\u00a0was taken in\u00a0the <a href=\"https:\/\/www.kitely.com\/virtual-world\/Ilan-Tochner\/Kitely-Welcome-Center\">Kitely Welcome Center<\/a>, which is a highly optimized world: a Script Time under 1 ms is a good result. However, if you see a high Script Time or Physics Time then the next\u00a0step is to find\u00a0which objects are causing the slowdown. In the\u00a0<strong>Region\/Estate<\/strong> dialog you can open one of two dialogs:\u00a0<strong>Top Colliders<\/strong> and\u00a0<strong>Top Scripts<\/strong>. The Top Colliders dialog shows the objects that use the most physics time, and the Top Scripts dialog shows the scripts that take the most time. With this information you can decide what to do: optimize\u00a0the objects, or disable\u00a0them.<\/p>\n<p><a href=\"https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/region-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2120\" src=\"https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/region-debug.png\" alt=\"Debug Region\" width=\"483\" height=\"540\" srcset=\"https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/region-debug.png 483w, https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/region-debug-268x300.png 268w\" sizes=\"auto, (max-width: 483px) 100vw, 483px\" \/><\/a><\/p>\n<p>We&#8217;ve already <a href=\"https:\/\/www.kitely.com\/virtual-world-news\/2014\/01\/22\/scripting-in-advanced-megaregions-and-troubleshooting-physics\/\">improved the Top Colliders dialog significantly<\/a> in the past, and today we made a similar improvement for Scripts.<\/p>\n<p><strong>Find and Fix Slow Scripts<\/strong><\/p>\n<p>Until today, the Script Time shown in the Statistics panel was\u00a0always 0! That statistic had never been implemented in OpenSim. Today&#8217;s update, at last, implements the\u00a0statistic. The &#8220;Script Time&#8221; value\u00a0now shows the amount of time spent executing the world&#8217;s scripts in the last frame. This value should usually be very low: ideally under 1 ms. Some worlds might legitimately need more Script Time, if they have many scripts or many animations, but usually if the Script Time is\u00a0higher than a few ms then you should\u00a0try to optimize some of the slowest scripts in your world.<\/p>\n<p>By the way,\u00a0the Script Time shown in the Statistics panel\u00a0is\u00a0<strong>independent\u00a0<\/strong>from all the other times shown in this panel. That&#8217;s because scripts execute on separate threads, outside of the frame processing time. This has two important implications. First, because scripts execute outside of the frame, it&#8217;s possible that the frame time will\u00a0<em>appear<\/em> to be good, even though in fact the world is operating slowly due to heavy scripts activity. Therefore, if you have a high Script Time then you should optimize your scripts, regardless of what the other statistics show. Second, it&#8217;s possible for the Script Time to be\u00a0<strong>very<\/strong> high, in some cases even hundreds of ms, i.e. longer than the frame time.<\/p>\n<p>If you see that your world is using a lot of script time then the next step is to find which scripts are causing the problem. To do this, open the\u00a0<strong>Top Scripts<\/strong> dialog. This dialog has been\u00a0<strong>vastly<\/strong> improved in\u00a0today&#8217;s update. Previously, the values it had shown\u00a0were practically useless. But now, this dialog shows an accurate list of the slowest scripts in the world, and measures their execution time precisely. The value shown for each script is the total time spent executing that\u00a0script in the last 30 seconds. (Note that 30 seconds is <em>much<\/em> longer than a single frame, and therefore the times shown here\u00a0have\u00a0little correlation with the Script Time shown in the statistics panel.)<\/p>\n<p><a href=\"https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/top-scripts.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2122\" src=\"https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/top-scripts.png\" alt=\"Top Scripts\" width=\"798\" height=\"377\" srcset=\"https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/top-scripts.png 798w, https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/top-scripts-300x142.png 300w, https:\/\/www.kitely.com\/virtual-world-news\/wp-content\/uploads\/2015\/08\/top-scripts-624x295.png 624w\" sizes=\"auto, (max-width: 798px) 100vw, 798px\" \/><\/a><\/p>\n<p>This screenshot was also taken in the Kitely Welcome Center. The top scripts here are pretty\u00a0fast: the slowest script took\u00a0just 5 ms, and remember that this is the total execution time over a 30-second period.<\/p>\n<p>If your world contains slow scripts then they&#8217;ll appear at the top of the list in this dialog, and you&#8217;ll be able to see that they take much more time than the rest of the scripts. Alternatively, another cause of\u00a0slow performance is if your scripts are efficient, but you have thousands of them. In that case you should consider\u00a0<em>why<\/em> you need so many scripts, and whether you can reduce their number. (Note that this dialog won&#8217;t show thousands of scripts, but if you see a hundred identical scripts then you may assume that there are thousands more behind\u00a0them&#8230;)<\/p>\n<p>Once you&#8217;ve found the slow scripts, edit them to make them faster. How to do this is out of scope for this blog post; if you need help, try asking in our <a href=\"https:\/\/www.kitely.com\/forums\/viewforum.php?f=26\">Scripting Forum<\/a>. Whenever you save the script, the new version starts executing immediately. Click &#8220;Refresh&#8221; in the Top Scripts dialog to see if your changes made the script faster. Keep in mind that this dialog shows the total execution\u00a0time in\u00a0the last\u00a030 seconds, so it will take some time for your changes to have an effect.<\/p>\n<p>Once you&#8217;ve optimized enough of the slow scripts, check\u00a0the Script Time in the Statistics panel to see if it has dropped significantly.<\/p>\n<p>If you don&#8217;t want to take the time to edit the scripts, or you&#8217;re in the middle of an event and you need to improve the world&#8217;s performance quickly, then you can use\u00a0the <strong>&#8220;Return Selected&#8221;<\/strong> or <strong>&#8220;Disable Selected&#8221;<\/strong> buttons in the dialog. &#8220;Return Selected&#8221; removes the selected objects from the world and adds them to your inventory. &#8220;Disable Selected&#8221; disables scripts\u00a0and physics on the selected objects. After using either of these buttons, you can immediately check the Statistics panel to see if the Script Time has dropped. If you Disabled the objects then remember to re-enable their scripts (and possibly their physics, if they&#8217;re physical objects) after you have optimized the scripts.<\/p>\n<p>We&#8217;re very proud of this feature.\u00a0One area in which OpenSim has lagged behind Second Life is in ensuring\u00a0a good (i.e., fast) experience for users. Every ex-Second Life user who switches to OpenSim enjoys the freedom to create large worlds with many prims and complex scripts, but this freedom can come at the cost of performance. At Kitely we&#8217;ve done a lot of work to make sure that <em>our <\/em>side of the service is fast, by using powerful servers and optimized asset and inventory systems. But\u00a0slow scripts can bring any world to its knees, no matter how fast the hardware it&#8217;s running on. Today&#8217;s update gives world managers the information they need to ensure that their worlds are snappy and enjoyable.<\/p>\n<p><strong>Contributing the New Script Features to OpenSim<\/strong><\/p>\n<p>After we&#8217;ve had some time to test this new feature on Kitely and ensure its quality, we&#8217;ll contribute this patch to the OpenSim project. This should improve the performance\u00a0of scripts everywhere in the Metaverse, to the benefit of the entire OpenSim community.<\/p>\n<p><strong>Other Improvements<\/strong><\/p>\n<p>We continued improving support for taking items\u00a0from\u00a0other grids and having them remain Exportable. This is a continuation of the work\u00a0described in <a href=\"https:\/\/www.kitely.com\/virtual-world-news\/2015\/07\/26\/improved-item-exchange-with-other-grids\/\">our last update<\/a>. If you encountered problems after the previous update then please get the affected objects from the third-party grid again now.<\/p>\n<p>When you view the list of members in a\u00a0Group, the list now shows for each member whether they&#8217;re online, or otherwise\u00a0the last time that they <em>were<\/em> online.<\/p>\n<p>The OSSL function\u00a0<a href=\"http:\/\/opensimulator.org\/wiki\/OsKey2Name\">osKey2Name<\/a> now returns the full name (including grid) for HG users. For example,\u00a0local users return\u00a0a name such as &#8220;First Last&#8221;, while Hypergrid users return\u00a0a name such as &#8220;First.Last @grid.example.com:8002&#8221;. (Previously Hypergrid users also returned a name such as &#8220;First Last&#8221;, so they couldn&#8217;t be differentiated from local users.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We updated our system today with several\u00a0new features. First, we vastly improved the ability to find\u00a0and fix slow scripts; this has a big impact on world performance. We&#8217;ll contribute this feature to the OpenSim project soon. Next, we continued to\u00a0improve support for items that were obtained in\u00a0other grids. Finally, we added a few features that &hellip; <a href=\"https:\/\/www.kitely.com\/virtual-world-news\/2015\/08\/05\/new-tools-for-fixing-slow-scripts\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">New Tools for Fixing Slow Scripts<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2116","post","type-post","status-publish","format-standard","hentry","category-virtual-worlds"],"_links":{"self":[{"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/posts\/2116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/comments?post=2116"}],"version-history":[{"count":12,"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/posts\/2116\/revisions"}],"predecessor-version":[{"id":2132,"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/posts\/2116\/revisions\/2132"}],"wp:attachment":[{"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/media?parent=2116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/categories?post=2116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kitely.com\/virtual-world-news\/wp-json\/wp\/v2\/tags?post=2116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}