Skip to content

Remove history btree #1861

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

Merged
merged 9 commits into from
Aug 16, 2023
Merged

Remove history btree #1861

merged 9 commits into from
Aug 16, 2023

Conversation

danlaine
Copy link

Why this should be merged

Using a buffer.Deque is faster than using a btree

How this works

Use deque instead of btree to hold changes sorted by increasing change number

How this was tested

Existing/updated UT

@danlaine danlaine added cleanup Code quality improvement merkledb labels Aug 15, 2023
@danlaine danlaine self-assigned this Aug 15, 2023
@@ -43,11 +45,11 @@ type change[T any] struct {

// Wrapper around a changeSummary that allows comparison
// of when the change was made.
type changeSummaryAndIndex struct {
type changeSummaryAndInsertNumber struct {
Copy link
Author

Choose a reason for hiding this comment

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

Kind of verbally clunky but I think InsertNumber is better than index since this isn't actually an index into anything, and I don't want people to think it's an index into history. I'm open to other names

// [lastEndRootChange] is the last change in the history resulting in [endRoot].
lastEndRootChange, ok := th.lastChanges[endRoot]
// [endRootChanges] is the last change in the history resulting in [endRoot].
endRootChanges, ok := th.lastChanges[endRoot]
Copy link
Author

Choose a reason for hiding this comment

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

Changed to endRootChanges for parallel naming with startRootChanges

@danlaine danlaine marked this pull request as ready for review August 15, 2023 20:03
@danlaine danlaine marked this pull request as draft August 15, 2023 20:04
@danlaine danlaine marked this pull request as ready for review August 15, 2023 21:06
// There's no change resulting in [startRoot] before the latest change resulting in [endRoot].
if startRootChanges.index > lastEndRootChange.index {
return nil, ErrStartRootNotFound
var (
Copy link
Contributor

Choose a reason for hiding this comment

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

should these be calculated after figuring out the insert number of the start root before the endroot?

Copy link
Author

Choose a reason for hiding this comment

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

the end root index has to be calculated here but I moved the start root index calculation below after we know startRootChanges is correct

Copy link
Author

Choose a reason for hiding this comment

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

I mean technically we could move this:

	var (
		// The insert number of the last element in [th.history].
		mostRecentChangeInsertNumber = th.nextInsertNumber - 1

		// The index within [th.history] of its last element.
		mostRecentChangeIndex = th.history.Len() - 1

		// The difference between the last index in [th.history] and the index of [endRootChanges].
		endToMostRecentOffset = int(mostRecentChangeInsertNumber - endRootChanges.insertNumber)

		// The index in [th.history] of the latest change resulting in [endRoot].
		endRootIndex = mostRecentChangeIndex - endToMostRecentOffset
	)

into the

if startRootChanges.insertNumber > endRootChanges.insertNumber {

clause and then recalculate the endRootIndex by using the startRootIndex later but I think it's cleaner as is

Dan Laine added 2 commits August 15, 2023 17:24
@danlaine danlaine merged commit 95ccae1 into dev Aug 16, 2023
@danlaine danlaine deleted the remove-history-btree branch August 16, 2023 14:37
marun pushed a commit that referenced this pull request Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement merkledb
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants