Skip to content

Performance: Add faster Any(...) Extensions for Array and List#9461

Merged
henon merged 2 commits intoMudBlazor:devfrom
xC0dex:feature/array-extensions
Jul 22, 2024
Merged

Performance: Add faster Any(...) Extensions for Array and List#9461
henon merged 2 commits intoMudBlazor:devfrom
xC0dex:feature/array-extensions

Conversation

@xC0dex
Copy link
Member

@xC0dex xC0dex commented Jul 20, 2024

Hey,

what do you think about this approach to gain some performance improvements? We are using Linq in some cases where it's not the best option regarding performance. With this little trick, we get a performance improvement as these Any methods will be used instead of the default Linq method. I think there are some more methods that we could add. We don't have to change existing code to make use of this.

Method Mean Error StdDev Allocated
Array_Any 1,165.1 ns 351.8 ns 19.28 ns 32 B
Array_Exists 508.8 ns 249.2 ns 13.66 ns -
List_Any 1,020.8 ns 342.4 ns 18.77 ns 40 B
List_FindIndex 518.8 ns 201.7 ns 11.06 ns -

Type of Changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added the enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library label Jul 20, 2024
@xC0dex
Copy link
Member Author

xC0dex commented Jul 20, 2024

@henon @ScarletKuro What's your opinion on that?

@danielchalmers
Copy link
Member

Fyi performance tag is probably more suitable than enhancement so it shows up differently in the changelog

@ScarletKuro
Copy link
Member

With this little trick, we get a performance improvement as these Any methods will be used instead of the default Linq method

I don't see any usage of Any(predicate) where the type is array or list in the core.

@codecov
Copy link

codecov bot commented Jul 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.53%. Comparing base (28bc599) to head (0de23be).
Report is 373 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #9461      +/-   ##
==========================================
+ Coverage   89.82%   90.53%   +0.70%     
==========================================
  Files         412      406       -6     
  Lines       11878    12715     +837     
  Branches     2364     2462      +98     
==========================================
+ Hits        10670    11511     +841     
+ Misses        681      641      -40     
- Partials      527      563      +36     

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

@xC0dex xC0dex added performance Time/memory/CPU/allocation performance characteristics and removed enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library labels Jul 20, 2024
@xC0dex
Copy link
Member Author

xC0dex commented Jul 20, 2024

Fyi performance tag is probably more suitable than enhancement so it shows up differently in the changelog

Thanks. I didn't know that such a label existed. I'll try to use the right labels in the future 👍

@xC0dex
Copy link
Member Author

xC0dex commented Jul 20, 2024

With this little trick, we get a performance improvement as these Any methods will be used instead of the default Linq method

I don't see any usage of Any(predicate) where the type is array or list in the core.

There are not many usages, but there are some:
image

I also saw that a private field is declared as IList instead of List. In such a case, the new extension method is not available.

@xC0dex
Copy link
Member Author

xC0dex commented Jul 20, 2024

There is a SonarCloud C# rule for this, that's where I had the idea from.

@xC0dex xC0dex marked this pull request as ready for review July 21, 2024 17:03
@henon
Copy link
Contributor

henon commented Jul 22, 2024

Why are they internal and not public ?

@henon
Copy link
Contributor

henon commented Jul 22, 2024

I guess if public they could cause conflicts with similar extensions of our users

@henon henon merged commit 31b6335 into MudBlazor:dev Jul 22, 2024
@henon henon changed the title feat: Add CollectionExtensions Performance: Add faster Any(...) Extensions for Array and List Jul 22, 2024
@xC0dex xC0dex deleted the feature/array-extensions branch July 22, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Time/memory/CPU/allocation performance characteristics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants