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

Feature: Don't clone values by default when retrieving values #26

Open
2 tasks done
tobiemh opened this issue Aug 10, 2022 · 0 comments
Open
2 tasks done

Feature: Don't clone values by default when retrieving values #26

tobiemh opened this issue Aug 10, 2022 · 0 comments
Labels
feature New feature or request help wanted Extra attention is needed topic:performance Improvements to database performance

Comments

@tobiemh
Copy link
Member

tobiemh commented Aug 10, 2022

Is your feature request related to a problem?

When fetching nested fields, array values, and remote records, we are currently cloning all values which are fetched. This has an impact on performance.

Describe the solution

Instead of using clone() by default when we are fetching or comparing fields , we should return Cow<'a, Value> values, resulting in a value only being cloned when it needs to be updated / written to.

We would also need to ensure that all Value types are based on Cow<'a, Value> values, as opposed to owned Value values.

So the following:

pub async fn get(&self, ctx: &Runtime, opt: &Options, txn: &Transaction, path: &[Part]) -> Result<Self, Error>;

would become:

pub async fn get(&'a self, ctx: &Runtime, opt: &Options, txn: &Transaction, path: &[Part]) -> Result<Cow<'a, Self>, Error>;

In addition, compute() functions would need to return Cow<'a, Value> values.

pub(crate) async fn compute(&'a self, ctx: &Context<'_>, opt: &Options, txn: &Transaction, doc: Option<&Value>) -> Result<Cow<'a, Value>, Error>

Alternative methods

Currently the functionality works without modification, but query performance will be significantly improved when this change is made.

SurrealDB version

surreal 1.0.0-beta.5 for macos on aarch64

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@tobiemh tobiemh added feature New feature or request topic:performance Improvements to database performance labels Aug 10, 2022
@tobiemh tobiemh changed the title Feature: Return references when retrieving values Feature: Don't clone values by default when retrieving values Aug 10, 2022
@tobiemh tobiemh added the help wanted Extra attention is needed label Aug 22, 2022
mumoshu added a commit to mumoshu/surrealdb that referenced this issue Aug 23, 2022
mumoshu added a commit to mumoshu/surrealdb that referenced this issue Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Extra attention is needed topic:performance Improvements to database performance
Projects
None yet
Development

No branches or pull requests

1 participant