Repository navigation
Conversation
| } | ||
| } | ||
| while (!endOfParagraph && DateTime.Now < stopTime); | ||
| while (!endOfParagraph && measureStopwatch.Elapsed < stopTimeout); |
There was a problem hiding this comment.
do you know how sensitive this code-path is to the accuracy of this measurement? the differences pointed out by SO make me wonder if we could possibly alter behavior that was dependent on the inaccuracy of this: https://stackoverflow.com/questions/2923283/stopwatch-vs-using-system-datetime-now-for-timing-events
There was a problem hiding this comment.
I don't know how sensitive the code is to the accuracy. I proposed this change not only for increased accuracy, but primarily for increased performance.
Accessing DateTime.Now is much slower than using a stopwatch. And every bit of performance gain we can achieve, especially if it's easy, should be taken, i guess.
I could write a benchmark to show the real difference if you want me to.
There was a problem hiding this comment.
It'll probably never matter, but DateTime.Now has correctness issues when being used for measuring timeouts or implementing timers, as the clock can be changed both manually and automatically (time zone changes esp. scheduled ones like summer/winter time changes can introduce an unexpected one hour delay). DateTime.UtcNow avoids the timezone problem and is faster than DateTime.Now but is still suspect to manual clock changes.
|
Hey @batzen, thanks for filing this issue and sending out a PR! Sorry for the lack of communication on this PR, we're all pretty new to working in OSS and haven't been the best at following through with things. I'd like to help get this PR moving along, since it seems like this is the right thing to do, I just want to make sure we aren't regressing anything. |
|
No worries, i didn't expect fast reactions as i already imagined that the whole team is busy open sourcing the code and getting it ready for the public. At the time i wrote the PR there were no tests and i could run, or i was unable to find those. |
|
@stevenbrix any news on this? |
|
To further explain my reasoning/hesitation on this change: I just want to make sure we've done our due diligence, because a 15-20% difference in a measurement seems like it could have unintended consequences. For example, if we're 20% slower and think that we're giving 200ms to read the paragraph, but in reality this completes in 220-230ms in most cases, then we have a change in behavior. Before we'd be exiting the loop because if (!endOfParagraph)
{
// Ran out of time. Defer to background layout.
SetFlags(true, Flags.BackgroundLayoutPending);
this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(OnBackgroundMeasure), null);
}
else
{
// Finished the entire document. Stop background layout.
SetFlags(false, Flags.BackgroundLayoutPending);
} |
|
Well, currently, by using DateTime the code suffers from these differences. It might change it's behavior on every invocation. Using a Stopwatch would make the behavior stable and predictable. |
|
@dotnet/wpf-developers any news on this one? |
|
This PR has passed smoke tests (DRTs) and is under review. |
|
@singhashish-wpf any news? The PR seems to have passed DRTs over two years ago. Has it been reviewed? |
This fixes #1170