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(TreeView): improve cache for TreeViewNode #4677

Merged
merged 13 commits into from
Nov 17, 2024
Merged

perf(TreeView): improve cache for TreeViewNode #4677

merged 13 commits into from
Nov 17, 2024

Conversation

kimdiego2098
Copy link
Collaborator

@kimdiego2098 kimdiego2098 commented Nov 16, 2024

Summary by Sourcery

Enhancements:

  • Optimize the TreeView component by replacing List with HashSet for node caches to improve virtual scrolling performance and reduce time complexity.

fixes #4687

Summary by Sourcery

Improve the performance of the TreeView component by using HashSet instead of List for node caches, enhancing virtual scrolling efficiency. Update tests to cover new functionality and ensure robustness.

Enhancements:

  • Optimize the TreeView component by replacing List with HashSet for node caches to improve virtual scrolling performance and reduce time complexity.

Tests:

  • Add new tests for the ModelHashSetComparer to ensure correct functionality and performance.

Copy link

sourcery-ai bot commented Nov 16, 2024

Reviewer's Guide by Sourcery

This PR improves the performance of the TreeView component by replacing List collections with HashSet for node caches. The implementation introduces a new HashSetComparer class and updates the caching mechanism to reduce time complexity during virtual scrolling operations.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Replace List collections with HashSet for node caches
  • Convert CheckedNodeCache, UncheckedNodeCache, and IndeterminateNodeCache from List to HashSet
  • Replace List operations (RemoveAll, Any) with more efficient HashSet operations (Remove, Contains)
  • Update cache initialization to use HashSet with custom comparer
  • Remove redundant existence checks before adding items to caches
src/BootstrapBlazor/Misc/TreeNodeCache.cs
src/BootstrapBlazor/Misc/ExpandableNodeCache.cs
Introduce new HashSet comparison functionality
  • Create new ModelHashSetComparer class for efficient HashSet operations
  • Add support for custom key attributes in hash code generation
  • Implement IEqualityComparer interface for type-safe comparisons
  • Remove old ModelComparer class
src/BootstrapBlazor/Misc/ModelHashSetComparer.cs
src/BootstrapBlazor/Misc/ModelComparer.cs
Update test suite for new HashSet implementation
  • Add new HashSetComparerTest class with comprehensive test cases
  • Update existing tests to use new HashSet-based cache implementation
  • Modify test field access to match new private field names
  • Add tests for custom key attribute handling
test/UnitTest/Utils/HashSetComparerTest.cs
test/UnitTest/Misc/TreeNodeCacheTest.cs
test/UnitTest/Components/TreeViewTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#4687 Improve cache performance for TreeViewNode by replacing List with HashSet

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

bb-auto bot commented Nov 16, 2024

Thanks for your PR, @kimdiego2098. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@bb-auto bb-auto bot requested a review from ArgoZhang November 16, 2024 14:47
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Nov 16, 2024
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @kimdiego2098 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang changed the title 优化TreeView组件 虚拟滚动性能,更换List为HashSet,降低时间复杂度 perf(TreeView): improve cache for TreeViewNode Nov 17, 2024
@bb-auto bb-auto bot added the enhancement New feature or request label Nov 17, 2024
@bb-auto bb-auto bot added this to the v9.0.0 milestone Nov 17, 2024
ArgoZhang
ArgoZhang previously approved these changes Nov 17, 2024
Copy link

codecov bot commented Nov 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (313ccb7) to head (33ba91f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #4677   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          620       620           
  Lines        27388     27388           
  Branches      3929      3926    -3     
=========================================
  Hits         27388     27388           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ArgoZhang
Copy link
Collaborator

@sourcery-ai review

@ArgoZhang ArgoZhang enabled auto-merge (squash) November 17, 2024 10:46
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Nov 17, 2024
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @kimdiego2098 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/BootstrapBlazor/Misc/HashSetComparer.cs Outdated Show resolved Hide resolved
@ArgoZhang
Copy link
Collaborator

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @kimdiego2098 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang merged commit c66f7dc into main Nov 17, 2024
5 checks passed
@ArgoZhang ArgoZhang deleted the treeview_dev branch November 17, 2024 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

perf(TreeView): improve cache for TreeViewNode
2 participants