Been developing an application which uses both Silverlight and Unity side-by-side in the web browser. However, we've found that when Unity is performing a lot of work (either due to complex scenes, underpowered hardware, etc) it was negatively impacting the performance of Silverlight to the point of no longer being usable.
We tried having Unity "idle" when not being directly interacted with by the user by dropping its frame rate using
I've profiled the processing of Silverlight, and considering the browser slowdown, I think the main browser process might not be triggering the main Silverlight runtime's loop. Once the loop executes, the code processes as quickly as ever, but the browser/runtime just waits and waits until Unity runs its update for its next frame. As soon as we set the
I put together a sample test that demonstrates this. Simply on the left-hand side in Silverlight, a smiley face follows the mouse cursor and on the right-hand side Unity displays a spinning cube. If you click the "Drop Frame Rate to 2 FPS" button in Unity, then continually move your mouse around in Silverlight, after about 10 seconds or so, you'll notice that the smiley face starts pausing instead of smoothly following your mouse. The performance continues to degrade until the smiley face updates are synchronized with Unity's frame rate (and even worse sometimes if it skips a frame). Click the "Increase Frame Rate to 60 FPS" will fix the performance, and clicking the 2 FPS button after will go through the same process of slowly degrading performance.
You can access the test here: http://sketcher.genexissystems.com/UnityFrameTest/
The only Silverlight code is:
And on Unity's side, the only pertinent code is:
So far we've tested and duplicated the slowdown on Windows XP and Windows 7 running on IE 8/9, Firefox 13/14, and Google Chrome 17/20. We've also found that the time needed to exhibit the slowdown can vary from operating system and browser though we have found that generally, Chrome takes the longest to slowdown and IE degrades the fastest.
This is created with Unity Pro 3.5.2f2.
Any thoughts or insights on this, or possible solutions would be greatly appreciated! Thank you!
EDIT: By the way, CPU usage during the tests never rose above 2% so this isn't an issue with one of them hogging the CPU, just thread waiting I guess.