Skip to content

Clean KeyedCollectionSlim.RemoveFirst method#3877

Merged
NGDAdmin merged 9 commits intomasterfrom
optimize-KeyedCollectionSlim
Apr 17, 2025
Merged

Clean KeyedCollectionSlim.RemoveFirst method#3877
NGDAdmin merged 9 commits intomasterfrom
optimize-KeyedCollectionSlim

Conversation

@shargon
Copy link
Member

@shargon shargon commented Apr 4, 2025

Description

An small optimization of KeyedCollectionSlim

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • RemoveFirst_ShouldRemoveFirstItem

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

var (_, time) = pendingKnownHashes.First;
if (oneMinuteAgo <= time) break;
pendingKnownHashes.RemoveFirst();
if (!pendingKnownHashes.RemoveFirst()) break;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this really necessary? looks like it will end the loop anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just use the return value instead of drop it

Copy link
Member

Choose a reason for hiding this comment

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

this is minor as Jimmy said.
Loop would be end anyway I think

@shargon shargon requested a review from Jim8y April 8, 2025 14:23
@shargon shargon changed the title Optimize KeyedCollectionSlim Clean KeyedCollectionSlim.RemoveFirst method Apr 9, 2025
@Jim8y Jim8y requested a review from Copilot April 9, 2025 10:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/Neo.IO/Caching/KeyedCollectionSlim.cs:28

  • Changing the GetKeyForItem parameter from TItem? to TItem requires ensuring that all subclass implementations guarantee a non-null item before calling this method.
protected abstract TKey GetKeyForItem(TItem item);

tests/Neo.UnitTests/IO/Caching/UT_KeyedCollectionSlim.cs:80

  • [nitpick] Consider adding a test case for when the collection is empty to verify that RemoveFirst returns false.
Assert.IsTrue(collection.RemoveFirst());

@Jim8y Jim8y requested review from Wi1l-B0t and cschuchardt88 April 9, 2025 10:18
private void OnTimer()
{
DateTime oneMinuteAgo = TimeProvider.Current.UtcNow.AddMinutes(-1);
var oneMinuteAgo = TimeProvider.Current.UtcNow.AddMinutes(-1);
Copy link
Member

Choose a reason for hiding this comment

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

this is still quite empirically calibrated. I remember when this was added.
We need to improve this logic at all.

@NGDAdmin NGDAdmin merged commit 2296a5d into master Apr 17, 2025
7 checks passed
@NGDAdmin NGDAdmin deleted the optimize-KeyedCollectionSlim branch April 17, 2025 02:19
Jim8y added a commit to Jim8y/neo that referenced this pull request Apr 17, 2025
* master:
  DBFTPlugin: include consensus time into block interval (neo-project#3900)
  Isolate unit tests (neo-project#3904)
  Use DateTime.UtcNow (neo-project#3902)
  Update workflow (neo-project#3901)
  optimize: show state more readable (neo-project#3899)
  Optimize KeyedCollectionSlim (neo-project#3877)
  Native: move MillisecondsPerBlock setting to native Policy (neo-project#3895)
  optimize: history command support (neo-project#3892)
  Ensure that view interops can't be changed outside (neo-project#3812)
cschuchardt88 pushed a commit to cschuchardt88/neo that referenced this pull request Jun 8, 2025
Co-authored-by: Jimmy <jinghui@wayne.edu>
Co-authored-by: Will <201105916+Wi1l-B0t@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants