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

chore: improve performance of ClearInternal #3863

Merged
merged 1 commit into from
Oct 4, 2024
Merged

chore: improve performance of ClearInternal #3863

merged 1 commit into from
Oct 4, 2024

Conversation

romange
Copy link
Collaborator

@romange romange commented Oct 4, 2024

Before:
BM_Clear/elements:32000 418763 ns 418749 ns 9965

After:
BM_Clear/elements:32000 323252 ns 323239 ns 12790

Before:
`BM_Clear/elements:32000     418763 ns       418749 ns         9965`

After:
`BM_Clear/elements:32000     323252 ns       323239 ns        12790`

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
@romange romange requested a review from kostasrim October 4, 2024 09:17
Copy link
Contributor

@kostasrim kostasrim left a comment

Choose a reason for hiding this comment

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

LGTM some minor comments in regards to code duplication

Comment on lines +291 to +293
dest.obj = link->Raw();
dest.has_ttl = link->HasTtl();
dest.ptr = link->next;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here second time I see this maybe worth making it a function. Actually we have the exact same boilerplate in the body of the for-loop from line 277 to 297. See https://github.com/dragonflydb/dragonfly/pull/3862/files#diff-5685b15a1d75a2c80b43908203ee74ab673f9a748f1dce35ad1f018bb656eb6aR236 with the only difference the function that gets called clone vs ObjDelete

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's not the same code because here we also call FreeLink

Comment on lines +196 to +202
if (ptr.IsObject()) {
dest.obj = ptr.Raw();
dest.ptr.Reset();
} else {
dest.ptr = ptr;
dest.obj = nullptr;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You merge very similar code in https://github.com/dragonflydb/dragonfly/pull/3862/files#diff-5685b15a1d75a2c80b43908203ee74ab673f9a748f1dce35ad1f018bb656eb6aR342 maybe worth extracting it into a function with an optional callback ?

Comment on lines +203 to 206
if (len == kArrLen) {
ClearBatch(kArrLen, arr);
len = 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice batching here :) Just curious why constexpr unsigned kArrLen = 32; ? Have you played around and increased this batch limt ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i did yeah. it can probably be differrent for differrent CPUs but it more or less near a sweet point

@romange romange merged commit 2e1d81a into main Oct 4, 2024
12 checks passed
@romange romange deleted the Pr2 branch October 4, 2024 11:26
kostasrim pushed a commit that referenced this pull request Oct 7, 2024
Before:
`BM_Clear/elements:32000     418763 ns       418749 ns         9965`

After:
`BM_Clear/elements:32000     323252 ns       323239 ns        12790`

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
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.

2 participants