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/spec binary search #3647

Merged
merged 5 commits into from
Nov 30, 2021
Merged

Perf/spec binary search #3647

merged 5 commits into from
Nov 30, 2021

Conversation

LukaszRozmej
Copy link
Member

Changes:

Binary search for spec transitions
Store head spec through calls

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bugfix (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)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe): performance

Testing

Requires testing

  • Yes
  • No

In case you checked yes, did you write tests??

  • Yes
  • No

return spec;
}
public IReleaseSpec GetSpec(long blockNumber) =>
_transitions.TryGetSearchedItem(blockNumber,
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary lambda allocation on GetSpec which is called very often

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed by static method

public IReleaseSpec GetSpec()
{
long headerNumber = _blockFinder.FindBestSuggestedHeader()?.Number ?? 0;
if (headerNumber == _lastHeader)
Copy link
Member

Choose a reason for hiding this comment

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

potential race condition

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

if (headerNumber == _lastHeader)
{
IReleaseSpec releaseSpec = _headerSpec;
if (headerNumber == _lastHeader)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the functionality so I need some clarification :)
GetSpec returns the best cached spec.
Does it have to be the latest? We don't have a monitor here, so it can change between ln54 and ln58. Which means we don't care if it's the latest. So if we don't care that it's the latest then we don't need that double check.

}
}

lock (_lock)
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, what if headerNumber changed between ln50 and ln65?
We will overwrite _headerSpec with the previous one.

@dceleda dceleda self-requested a review November 30, 2021 10:57
@LukaszRozmej LukaszRozmej merged commit a0f55f6 into master Nov 30, 2021
@LukaszRozmej LukaszRozmej deleted the perf/spec_binary_search branch November 30, 2021 16:18
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