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

perf: Make ViewModelBase's internal errors dictionary lazy initialized #94

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

jeanplevesque
Copy link
Member

@jeanplevesque jeanplevesque commented Dec 15, 2023

GitHub Issue: #

Proposed Changes

  • Bug fix
  • Feature
  • Code style update (formatting)
  • Refactoring (no functional changes, no api changes)
  • Build or CI related changes
  • Documentation content changes
  • Other, please describe: Performance optimization

What is the current behavior?

  • The internal _errors dictionary for the INotifyDataErrorInfo aspect of ViewModelBase is always instantiated, even if the INotifyDataErrorInfo features aren't used for a ViewModel.
  • The _errors dictionary is a ConcurrentDictionary.
Method Mean Allocated
CreateViewModel 2.057 μs 1760 B
CreateViewModel_WithExplicitName 2.077 μs 1760 B

What is the new behavior?

  • The _errors field is now a Dictionary. We weren't using any features specific to ConcurrentDictionary.
  • The _errors field is now lazy-initialized. It stays null as long a we don't call SetErrors.
Method Mean Allocated
CreateViewModel 1.280 μs 936 B
CreateViewModel_WithExplicitName 1.193 μs 936 B

Impact on version

  • Major (Public API was modified.)
    • Public constructs (class, struct, delegate, enum, etc.) were removed or renamed.
    • Public members were removed or renamed.
    • Public method signatures were changed or renamed.
  • Minor (Public API was extended.)
    • Public constructs, members, or overloads were added.
  • Patch (Public API was unchanged.)
    • A bug in behavior was fixed.
    • Documentation was changed.
  • None (The library is unchanged.)
    • Only code under the build folder was changed.
    • Only code under the .github folder was changed.

Checklist

Please check that your PR fulfills the following requirements:

  • Documentation has been added/updated.
  • Automated Unit / Integration tests for the changes have been added/updated.
  • Updated BREAKING_CHANGES.md (if you introduced a breaking change).
  • Your conventional commits are aligned with the Impact on version section.

Other information

@jeanplevesque jeanplevesque requested a review from a team December 15, 2023 20:00
@jeanplevesque jeanplevesque requested a review from a team December 18, 2023 13:42
@jeanplevesque jeanplevesque merged commit ae4b349 into main Dec 18, 2023
4 checks passed
@jeanplevesque jeanplevesque deleted the dev/jpl/lazy-errors branch December 18, 2023 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants