Skip to content

Conversation

@kimdiego2098
Copy link
Collaborator

@kimdiego2098 kimdiego2098 commented Jun 16, 2025

Issues

close #6239

字典操作很频繁,增加一点点性能

Summary by Sourcery

Use reference equality comparer for table column caches to reduce dictionary overhead and improve performance

Enhancements:

  • Initialize LastFixedColumnCache with ReferenceEqualityComparer.Instance
  • Initialize FirstFixedColumnCache with ReferenceEqualityComparer.Instance

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 16, 2025

Reviewer's Guide

This pull request enhances dictionary lookup performance by configuring the two ConcurrentDictionary caches to use reference equality when comparing ITableColumn keys.

Sequence Diagram: Cache Lookup Using Reference Equality

sequenceDiagram
    participant Caller as "IsLastColumn / IsFirstColumn"
    participant Cache as "ConcurrentDictionary (e.g., LastFixedColumnCache)"
    participant REC as "ReferenceEqualityComparer.Instance"
    participant KeyToLookup as "ITableColumn (key)"

    Caller->>Cache: GetOrAdd(KeyToLookup, valueFactory)
    activate Cache
    Cache->>REC: Equals(KeyToLookup, existingCacheKey)
    activate REC
    REC-->>Cache: bool (reference equality result)
    deactivate REC
    alt Key found by reference
        Cache-->>Caller: CachedValue
    else Key not found or different reference
        Cache-->>Caller: NewValue (after computing and storing)
    end
    deactivate Cache
Loading

Class Diagram: Table Cache Configuration Update

classDiagram
    class Table {
        -LastFixedColumnCache: ConcurrentDictionary~ITableColumn, bool~
        -FirstFixedColumnCache: ConcurrentDictionary~ITableColumn, bool~
        +IsLastColumn(col: ITableColumn) : bool
        +IsFirstColumn(col: ITableColumn) : bool
    }
    class ConcurrentDictionary~TKey, TValue~ {
        +ConcurrentDictionary(comparer: IEqualityComparer~TKey~)
    }
    class ReferenceEqualityComparer {
        <<static>> +Instance : IEqualityComparer
    }
    class ITableColumn {
        <<interface>>
    }

    Table o-- "2" ConcurrentDictionary : has caches
    Table ..> ReferenceEqualityComparer : uses Instance for initializing caches
    ConcurrentDictionary ..> ITableColumn : TKey for caches
Loading

File-Level Changes

Change Details Files
Use ReferenceEqualityComparer for dictionary caches to optimize key comparisons
  • Initialize LastFixedColumnCache with ReferenceEqualityComparer.Instance
  • Initialize FirstFixedColumnCache with ReferenceEqualityComparer.Instance
src/BootstrapBlazor/Components/Table/Table.razor.Sort.cs

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

@bb-auto
Copy link

bb-auto bot commented Jun 16, 2025

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 June 16, 2025 06:41
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jun 16, 2025
Copy link
Contributor

@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!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Table/Table.razor.Sort.cs:247` </location>
<code_context>
     private bool IsLastExtendButtonColumn() => IsExtendButtonsInRowHeader && !GetVisibleColumns().Any(i => i.Fixed);

-    private ConcurrentDictionary<ITableColumn, bool> FirstFixedColumnCache { get; } = new();
+    private ConcurrentDictionary<ITableColumn, bool> FirstFixedColumnCache { get; } = new(ReferenceEqualityComparer.Instance);

     private bool IsFirstColumn(ITableColumn col) => FirstFixedColumnCache.GetOrAdd(col, col =>
</code_context>

<issue_to_address>
Double-check use of reference equality for columns

ReferenceEqualityComparer requires that the same column object instance is used consistently; otherwise, cache misses may occur. Confirm this behavior is intentional.
</issue_to_address>

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.

@codecov
Copy link

codecov bot commented Jun 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2104888) to head (8bfb6ff).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6238   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          704       704           
  Lines        31121     31121           
  Branches      4400      4400           
=========================================
  Hits         31121     31121           
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kimdiego2098
Copy link
Collaborator Author

image

默认的EqualityComparer.Default 比较器,渲染造成比较大的性能消耗

@ArgoZhang ArgoZhang changed the title 缓存字典设置引用比较器 perf(Table): use ReferenceEqualityComparer instance Jun 16, 2025
@bb-auto bb-auto bot added the enhancement New feature or request label Jun 16, 2025
@bb-auto bb-auto bot added this to the 9.7.0 milestone Jun 16, 2025
@ArgoZhang ArgoZhang merged commit bed5200 into main Jun 16, 2025
6 checks passed
@ArgoZhang ArgoZhang deleted the table_sort branch June 16, 2025 09:22
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(Table): use ReferenceEqualityComparer instance

3 participants