Bug 32129 - Labels are being re-drawn unnecessarily. Performance implications.
Summary: Labels are being re-drawn unnecessarily. Performance implications.
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 1.4.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-07-20 04:05 UTC by John Hardman
Modified: 2016-04-11 08:30 UTC (History)
2 users (show)

Tags: xamarin.forms winphone labels redrawing performance ngf
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description John Hardman 2015-07-20 04:05:48 UTC
Whilst re-factoring some code, I enabled EnableRedrawRegions in the App.xaml.cs for my app's WinPhone 8 project, using the line:

Application.Current.Host.Settings.EnableRedrawRegions = true;


As I exercised different parts of my app, I noticed that some Labels were being redrawn unnecessarily. On some reasonably complex pages, the Labels being redrawn had no obvious connection to the parts of the page that were intentionally being updated. I have put together a much cut down version of one page, removing the vast majority of Views and code. The code is below.


In this sample, when the Slider is moved, I would expect just one Label to be redrawn, but actually three Labels are being redrawn on my Nokia phone. This has performance implications, and potentially unexpected behaviour on more complex pages.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xamarin.Forms;

namespace App1
{
    public class App : Application
    {
        private Label _labelToChange;
        private Slider _sliderThatWeMove;

        private void OnSliderChanged(object sender, ValueChangedEventArgs e)
        {
            int newValue = (int)(e.NewValue + 0.5);
            String desiredValue = newValue.ToString();
            if (desiredValue != _labelToChange.Text)
                _labelToChange.Text = desiredValue;
        }

        public App()
        {
            _labelToChange = new Label
            {
                Text = "44",
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions = LayoutOptions.End
            };

            _sliderThatWeMove = new Slider
            {
                Maximum = 255,
                Minimum = 0,
                Value = 44,

                HorizontalOptions = LayoutOptions.Fill, // AndExpand,
                VerticalOptions = LayoutOptions.Start
            };

            _sliderThatWeMove.ValueChanged += OnSliderChanged;

            MainPage = new ContentPage
            {
                Title="ObfuscatedString1",

                Content = new StackLayout
                {
                    Orientation = StackOrientation.Vertical,

                    HorizontalOptions = LayoutOptions.Fill,
                    VerticalOptions = LayoutOptions.Fill,

                    Children = // of StackLayout
                    {
                        new Label
                        {
                            Text="Why redrawn #1 ?",

                            HorizontalOptions = LayoutOptions.Start,
                            VerticalOptions = LayoutOptions.Start

                        },
                        new StackLayout
                        {
                            VerticalOptions = LayoutOptions.CenterAndExpand,
                        },
                        new StackLayout
                        {
                            Orientation = StackOrientation.Vertical,

                            HorizontalOptions = LayoutOptions.Fill,
                            VerticalOptions = LayoutOptions.End,

                            Children = // of StackLayout
                            {
                                new Label
                                {
                                    Text="Why redrawn #2 ?",
                                    HorizontalOptions = LayoutOptions.Start,
                                    VerticalOptions = LayoutOptions.Start

                                },
                                _labelToChange,
                                _sliderThatWeMove

                            } // Children of StackLayout
                        } // StackLayout
                    } // Children of StackLayout
                } // StackLayout
            }; // ContentPage
        } // constructor
    } // class
} // namespace
Comment 1 Jason Smith [MSFT] 2015-07-27 11:11:19 UTC
Not all layouts have all possible performance optimizations yet. This is effectively what you are seeing. This isn't an explicit draw call to the label, simply it's being re-laid out.
Comment 2 Jason Smith [MSFT] 2016-04-11 08:30:15 UTC
2.1.0 has significant improvements with regards to this, I am closing this to reflect those changes.