x


Low Application.targetFrameRate slows Silverlight/Browser too

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 Application.targetFrameRate. Initially, it works great and the Silverlight performance shoots back up through the roof. However, the performance degrades to the point where Silverlight starts running at the same framerate as Unity. It also seems to affect the browser overall (closing the window, interacting with it can become delayed).

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 Application.targetFrameRate back up to 60fps, everything works fine again (albeit with the degraded performance we were trying to solve in the first place)

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:

public MainPage()
{
    InitializeComponent();

    MouseMove += MainPage_MouseMove;
}

private void MainPage_MouseMove(object sender, MouseEventArgs e)
{
    var position = e.GetPosition(this);
    this.image1.Margin = new Thickness(position.X - image1.Width / 2, position.Y - image1.Height / 2, 0, 0);
}

And on Unity's side, the only pertinent code is:

public class ChangeFrameRate : MonoBehaviour
{
    private void Start()
    {
        QualitySettings.vSyncCount = 0;
        Application.runInBackground = true;
    }

    private void OnGUI()
    {
        if (GUI.Button(new Rect(0, 0, 250, 20), "Drop Frame Rate to 2 FPS"))
            Application.targetFrameRate = 2;

        if (GUI.Button(new Rect(0, 30, 250, 20), "Increase Frame Rate to 60 FPS"))
            Application.targetFrameRate = 60;
    }
}

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.

more ▼

asked Jul 20, 2012 at 08:06 PM

Chris Sinclair gravatar image

Chris Sinclair
31 6 4 6

FYI doesn't happen on my Mac running Chrome.

Jul 20, 2012 at 09:35 PM whydoidoit

@whydoidoit thanks for the mac test; good to hear!

Jul 20, 2012 at 09:37 PM Chris Sinclair
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1120
x1049
x270
x24

asked: Jul 20, 2012 at 08:06 PM

Seen: 946 times

Last Updated: Jul 20, 2012 at 09:37 PM