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

refactor: avoid unnecessary allocation #3747

Closed
wants to merge 1 commit into from

Conversation

WenyXu
Copy link
Member

@WenyXu WenyXu commented Apr 19, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

avoid unnecessary allocation

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR does not require documentation updates.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Apr 19, 2024
@WenyXu WenyXu changed the title refactor: avoid unnecessary cloning refactor: avoid unnecessary allocation Apr 19, 2024
@waynexia waynexia enabled auto-merge April 19, 2024 06:34
Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.30%. Comparing base (0c5f480) to head (551bdaf).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3747      +/-   ##
==========================================
- Coverage   85.65%   85.30%   -0.36%     
==========================================
  Files         944      944              
  Lines      158776   158772       -4     
==========================================
- Hits       135997   135437     -560     
- Misses      22779    23335     +556     

Copy link
Contributor

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

When you use Vec<&'a [u8]>, an extra allocation happen at

                                    PutRequest::new()
                                        .with_key(key.into_bytes())
                                        .with_value(value),

where

    pub fn with_value(mut self, value: impl Into<Vec<u8>>) -> Self {
        self.value = value.into();
        self
    }

impl<T: Clone> From<&[T]> for Vec<T> {
    fn from(s: &[T]) -> Vec<T> {
    /// Allocate a `Vec<T>` and fill it by cloning `s`'s items.
        s.to_vec()
    }
}

See also #3740 (comment)

@tisonkun tisonkun disabled auto-merge April 19, 2024 06:44
@evenyag
Copy link
Contributor

evenyag commented Apr 19, 2024

When you use Vec<&'a [u8]>, an extra allocation happen at

                                    PutRequest::new()
                                        .with_key(key.into_bytes())
                                        .with_value(value),

where

    pub fn with_value(mut self, value: impl Into<Vec<u8>>) -> Self {
        self.value = value.into();
        self
    }

impl<T: Clone> From<&[T]> for Vec<T> {
    fn from(s: &[T]) -> Vec<T> {
    /// Allocate a `Vec<T>` and fill it by cloning `s`'s items.
        s.to_vec()
    }
}

See also #3740 (comment)

Got it. I'm going to close this @WenyXu

@evenyag evenyag closed this Apr 19, 2024
@tisonkun
Copy link
Contributor

tisonkun commented Apr 19, 2024

But actually IntoChunks and collect makes new vecs also. So it won't be quite differnt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants