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

Add BlobFetcherCopyReadOptions #11236

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

rockeet
Copy link
Contributor

@rockeet rockeet commented Feb 19, 2023

BlobFetcher has a copy of ReadOptions which waste CPU.

This PR optimized this copy of ReadOptions to a reference, also add BlobFetcherCopyReadOptions for long lived BlobFetcher object.

};

class BlobFetcherCopyReadOptions : public BlobFetcher {
Copy link
Contributor

Choose a reason for hiding this comment

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

This naming BlobFetcherCopyReadOptions sounds like it's a type of ReadOptions than BlobFetcher. How about BlobFetcherWithReadOptionsCopy.

};

class BlobFetcherCopyReadOptions : public BlobFetcher {
const ReadOptions read_options_copy_;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit suggestion: how about moving the data members to be after the function members and set its private section explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's OK, done!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit suggestion: how about moving the data members to be after the function members and set its private section explicitly?

Done!

class BlobFetcherWithReadOptionsCopy : public BlobFetcher {
public:
BlobFetcherWithReadOptionsCopy(const Version* v, const ReadOptions& ro)
: BlobFetcher(v, read_options_copy_), read_options_copy_(ro) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

If BlobFetcher uses this reference in its constructor, it will cause some hard to find bugs. This subclass is enforcing an unusual requirement on its base class. Future users of BlobFetcher needs to be conscious of the scope of their ReadOptions relative to their BlobFetcher in order to choose the right one of the two. This at least requires more documentation of this class. I wonder if the copying saved is worth introducing this pattern. Checking with @ltamasi to make a call here.

Copy link
Contributor

@ltamasi ltamasi Oct 9, 2023

Choose a reason for hiding this comment

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

Thanks @jowlyzhang ! I agree that reference members are pretty accident prone: as an example, if BlobFetcher ever started to use read_options_ in its destructor, BlobFetcherWithReadOptionsCopy would break since the ReadOptions in the derived class would have been destroyed by the time the base class destructor runs.

@rockeet The goal of the PR is to save the ReadOptions copy that happens in Version::Get and Version::MultiGet, right? We could achieve that by changing GetContext so it takes a back pointer to Version (instead of a BlobFetcher pointer) and calls Version::GetBlob directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could achieve that by changing GetContext so it takes a back pointer to Version (instead of a BlobFetcher pointer) and calls Version::GetBlob directly.

Hm, actually, scratch that - the key issue is how we're going to access the ReadOptions struct since GetContext doesn't have access to it either. Yeah, saving this copy might not be worth the extra complexity then.

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.

None yet

4 participants