Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Core] Run only one forceSizeUpdate per 16 milliseconds #2040

Closed
wants to merge 6 commits into from
Closed

[Core] Run only one forceSizeUpdate per 16 milliseconds #2040

wants to merge 6 commits into from

Conversation

AndreiMisiukevich
Copy link
Contributor

@AndreiMisiukevich AndreiMisiukevich commented Mar 7, 2018

Description of Change

fixes #2039

Changed:

  • object Cell => OnForceUpdateSizeRequested

Behavioral Changes

Run only one forceSizeUpdate per 16 milliseconds

@samhouts samhouts changed the title Possible fix for Xamarin.Forms/issues/2039 [Core] Run only one forceSizeUpdate per 16 milliseconds Mar 7, 2018
@@ -19,6 +19,9 @@ public abstract class Cell : Element, ICellController, IFlowDirectionController

bool _nextCallToForceUpdateSizeQueued;

object _forceUpdateSizeLocker = new object();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like indentation is out of place here and on other lines as well.

@AndreiMisiukevich
Copy link
Contributor Author

@adrianknight89 sorry, it was my gap.. I had to uncheck "converting tabs to spaces"

@jassmith
Copy link

jassmith commented Mar 7, 2018

build

@jassmith
Copy link

jassmith commented Mar 7, 2018

I dont understand the point of this? Screen refresh rates can be greater than 60hz

@@ -19,6 +19,9 @@ public abstract class Cell : Element, ICellController, IFlowDirectionController

bool _nextCallToForceUpdateSizeQueued;

object _forceUpdateSizeLocker = new object();
Task _forceUpdateSizeDelayTask = Task.CompletedTask;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compile error here:

Cells\Cell.cs(23,41): error CS0117: 'Task' does not contain a definition for 'CompletedTask' [C:\agent_work\2\s\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this error by replacing Task.CompletedTask by Task.FromResult(true)

@AndreiMisiukevich
Copy link
Contributor Author

@jassmith I can't answer, nevertheless I noticed, that the implementation doesn't correspond to presented comment - "don't run more than once per 16 milliseconds"

look through initial code
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/Cells/Cell.cs#L211-L218

So, I aligned code according to presented comment.

@AndreiMisiukevich
Copy link
Contributor Author

Now, I hope, it will be built successfully

@jassmith
Copy link

jassmith commented Mar 7, 2018

I apologize, I was skipping through these notifications very fast and failed to properly read the diff. I remember why this is rate limited now. Its SUPER expensive :P

@jassmith
Copy link

jassmith commented Mar 7, 2018

build

@rmarinho
Copy link
Member

rmarinho commented Mar 7, 2018

@AndreiMisiukevich unit test failed

@hartez
Copy link
Contributor

hartez commented Mar 7, 2018

@AndreiMisiukevich I do not understand why the original version would run more than once every 16 milliseconds. Are you worried about this being called from multiple threads?

@AndreiMisiukevich
Copy link
Contributor Author

AndreiMisiukevich commented Mar 7, 2018

@hartez yes, exactly. If write smth like code below

	class VCell : ViewCell
	{
		protected override void OnTapped()
		{
			base.OnTapped();

			foreach(var task in Enumerable.Range(0, 10).Select(i => new Task(ForceUpdateSize)))
			{
				task.Start();
			}
		}
	}

@jassmith
Copy link

jassmith commented Mar 8, 2018

Calling ForceUpdateSize from a non-UI thread is not supported.

@hartez
Copy link
Contributor

hartez commented Mar 8, 2018

@AndreiMisiukevich @jassmith I am guessing that most handlers of that event need to run on the main thread. Perhaps it would make more sense to marshal all the calls to OnForceUpdateSizeRequested onto the main thread in the first place. Something like:

public void ForceUpdateSize()
{
	if (_nextCallToForceUpdateSizeQueued)
		return;

	if ((Parent as ListView)?.HasUnevenRows == true)
	{
		Device.BeginInvokeOnMainThread(() => {
			_nextCallToForceUpdateSizeQueued = true;
			OnForceUpdateSizeRequested();
		});
	}
}

@AndreiMisiukevich
Copy link
Contributor Author

AndreiMisiukevich commented Mar 8, 2018

Okay, i see.
But I think it would be better if we wait only necessary time (without default 16 milliseconds waiting every call)

I added new commit. see it above

@jassmith
Copy link

jassmith commented Mar 8, 2018

Thats not a bad point. Restarting your builds again. You probably should just null check that Task instead of Task.Delay(0) it, that is just waste.

@AndreiMisiukevich
Copy link
Contributor Author

so @jassmith, what do you think about Device.BeginInvokeInMainThread(OnForceUpdateSizeRequested) as @hartz said?

@jassmith
Copy link

jassmith commented Mar 8, 2018

I dont want us to auto-marshal everything no. Supporting out of UI thread calls in just this one area will cause us more confusion than its worth.

@AndreiMisiukevich
Copy link
Contributor Author

Colleagues, I think these changes aren't very important, are they?
Should I close/discard this PR?

@rmarinho
Copy link
Member

Does it show any visual change' like is the list faster , smoother ?

@rmarinho
Copy link
Member

We will not be taking this at this time.

@karlingen
Copy link

@AndreiMisiukevich @rmarinho Why is this closed? This is still an issue. See #2735

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ForceUpdateSize Delay issue
7 participants