Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrease CPU usage of OverflowTextBlock + optimization #403

Merged
merged 7 commits into from
Apr 18, 2019
Merged

Decrease CPU usage of OverflowTextBlock + optimization #403

merged 7 commits into from
Apr 18, 2019

Conversation

rudyhuyn
Copy link
Contributor

@rudyhuyn rudyhuyn commented Mar 28, 2019

Fixes #402 and #414

Divide by 4 the CPU usage of OverflowTextBlock when buttons are pressed very quickly.

Snag_e26b41

Description of the changes:

Xaml-side:

  • OverflowTextBlock has some performance issues:
    • double scrollviewer: the listview was in a scrollviewer, while the control already containing one -> it breaks the virtualization of the listview and impacts on UI performance.
    • The listview used a StackPanel, this panel doesn't support virtualization of ListViewItems contrary to ItemsStackPanel
    • No ListView-specific features were used, an ItemsControl is more efficient and lighter.
  • refactor how we manage the visibility of the left/right buttons in OverflowTextBlock, the new version is more reactive and will not display the right arrow when not necessary (see GIF below).
  • remove the ItemContainerSelector ExpressionItemContainerStyle, not really used by OverflowTextBlock
  • remove UI glitches generated by ChangeView when users type fast (control partially hidden and scrolling issues, see the GIF below).
  • only modify the accessibility view when it's necessary

ViewModel-side:

  • stop fully refreshing ExpressionTokens in StandardCalculatorViewModel when a new command were sent, instead, use a IObservableVector to only send new tokens to the UI (in average only 1 or 2 UI items are refreshed while the full expression was refreshed before)

Demo:
A0D05EB6-A342-4AD9-BE6C-D4FD51E97733

How changes were validated:

Manually

- optimize ExpressionTokens in StandardCalculatorViewModel to only update new tokens instead of the full list
- refactor how we manage the visibility of left/right buttons
- remove useless ExpressionItemContainerStyle
- only modify accessbility view if necessary
@rudyhuyn rudyhuyn changed the title Optimize performance and CPU usage of OverflowTextBlock Decrease CPU usage of OverflowTextBlock + optimizations Mar 28, 2019
@rudyhuyn rudyhuyn changed the title Decrease CPU usage of OverflowTextBlock + optimizations Decrease CPU usage of OverflowTextBlock + optimization Mar 28, 2019
src/CalcViewModel/StandardCalculatorViewModel.cpp Outdated Show resolved Hide resolved
src/CalcViewModel/StandardCalculatorViewModel.cpp Outdated Show resolved Hide resolved
src/Calculator/Controls/OverflowTextBlock.cpp Outdated Show resolved Hide resolved
src/Calculator/Controls/OverflowTextBlock.cpp Outdated Show resolved Hide resolved
src/Calculator/Controls/OverflowTextBlock.h Outdated Show resolved Hide resolved
src/Calculator/Views/Calculator.xaml Outdated Show resolved Hide resolved
…ate to make this control customizable by other developers
@@ -30,25 +30,38 @@ DEPENDENCY_PROPERTY_INITIALIZATION(OverflowTextBlock, TokensUpdated);

void OverflowTextBlock::OnApplyTemplate()
{
assert(((m_scrollLeft == nullptr) && (m_scrollRight == nullptr)) || ((m_scrollLeft != nullptr) && (m_scrollRight != nullptr)));
UnregisterEventHandlers();
Copy link
Contributor Author

@rudyhuyn rudyhuyn Apr 17, 2019

Choose a reason for hiding this comment

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

slight refactoring to make this control more customizable (in case developers want to use it in their own apps):

  • can apply a template more than 1 time
  • make controls optional

Copy link

@danbelcher-MSFT danbelcher-MSFT left a comment

Choose a reason for hiding this comment

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

The change looks good. Thanks, Rudy!

@danbelcher-MSFT danbelcher-MSFT merged commit de65db6 into microsoft:master Apr 18, 2019
EriWong pushed a commit to EriWong/calculator that referenced this pull request Jun 5, 2019
Fixes microsoft#402 and microsoft#414
Divide by 4 the CPU usage of OverflowTextBlock when buttons are pressed very quickly.

Description of the changes:

Xaml-side:
OverflowTextBlock has some performance issues:
double scrollviewer: the listview was in a scrollviewer, while the control already containing one -> it breaks the virtualization of the listview and impacts on UI performance.
The listview used a StackPanel, this panel doesn't support virtualization of ListViewItems contrary to ItemsStackPanel

No ListView-specific features were used, an ItemsControl is more efficient and lighter.
refactor how we manage the visibility of the left/right buttons in OverflowTextBlock, the new version is more reactive and will not display the right arrow when not necessary (see GIF below).
remove the ItemContainerSelector ExpressionItemContainerStyle, not really used by OverflowTextBlock

remove UI glitches generated by ChangeView when users type fast (control partially hidden and scrolling issues, see the GIF below).
only modify the accessibility view when it's necessary

ViewModel-side:
stop fully refreshing ExpressionTokens in StandardCalculatorViewModel when a new command were sent, instead, use a IObservableVector to only send new tokens to the UI (in average only 1 or 2 UI items are refreshed while the full expression was refreshed before)

How changes were validated:
Manually
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clicking negate more than ten times progressively slows UI responsiveness
3 participants