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

feat(cubesql): CubeScan - don't clone strings for non stream response #8633

Merged
merged 5 commits into from
Aug 26, 2024

Conversation

ovr
Copy link
Member

@ovr ovr commented Aug 26, 2024

image

FieldValue is used as an abstraction between transport results and building columnar data for data fusion. We don't need to clone strings because they are used as a reference for the arrow's StringBuilder. It uses its own slice under the hood.

Copy link

vercel bot commented Aug 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-angular-dashboard ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 3:27pm
examples-react-d3 ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 3:27pm
examples-react-dashboard ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 3:27pm
examples-react-data-table ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 3:27pm
examples-react-highcharts ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 3:27pm
examples-react-material-ui ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 3:27pm
examples-react-pivot-table ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 3:27pm
examples-vue-query-builder ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 3:27pm

@ovr ovr marked this pull request as ready for review August 26, 2024 13:12
@ovr ovr requested a review from a team as a code owner August 26, 2024 13:12
Ok(match value {
Value::String(s) => FieldValue::String(s),
Value::String(s) => FieldValue::StringRef(s),
Value::Number(n) => FieldValue::Number(n.as_f64().ok_or(
Copy link
Member Author

Choose a reason for hiding this comment

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

There is an additional boost here (we don't clone it), while n is used as a reference.

image

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 73.17073% with 11 lines in your changes missing coverage. Please review.

Project coverage is 82.50%. Comparing base (7538fe6) to head (c9e0774).
Report is 3 commits behind head on master.

Files Patch % Lines
rust/cubesql/cubesql/src/compile/engine/df/scan.rs 73.17% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8633      +/-   ##
==========================================
- Coverage   82.50%   82.50%   -0.01%     
==========================================
  Files         209      209              
  Lines       76711    76718       +7     
==========================================
+ Hits        63293    63298       +5     
- Misses      13418    13420       +2     
Flag Coverage Δ
cubesql 82.50% <73.17%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

String(String),
// Best variant for us with strings, because we dont need to clone string
StringRef(&'a String),
Copy link
Member

Choose a reason for hiding this comment

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

Why not reference to str? I don't think reference to String gets us anything functionally, but ties to specific allocation pattern.

Copy link
Member Author

Choose a reason for hiding this comment

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

'str cannot be used because I combine branches via |. In Rust, it is a requirement to align them to the same type for usage.

@@ -446,8 +446,11 @@ struct CubeScanExecutionPlan {
}

#[derive(Debug)]
pub enum FieldValue {
pub enum FieldValue<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

Add meaningful name for lifetime, like 'str/`'string' please

Copy link
Member

Choose a reason for hiding this comment

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

I believe it's pretty much the convention to have it as 'a at least when you only have one lifetime to care about. It's pretty easy to follow with one lifetime.

Copy link
Member Author

Choose a reason for hiding this comment

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

With Cow<'str, str> is not an option because it's meme

index: usize,
field_name: &str,
) -> std::result::Result<FieldValue, CubeError> {
let option = self.rows[index].as_object_mut();
let as_object = if let Some(as_object) = option {
let as_object = if let Some(as_object) = self.rows[index].as_object() {
Copy link
Member

Choose a reason for hiding this comment

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

Can be represented as let Some(as_object) = ... else {}

@mcheshkov
Copy link
Member

Given that we now have both owned and borrowed variants in FieldValue maybe we should merge them to single String containing Cow<'a, str>?

@@ -446,8 +446,11 @@ struct CubeScanExecutionPlan {
}

#[derive(Debug)]
pub enum FieldValue {
pub enum FieldValue<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

I believe it's pretty much the convention to have it as 'a at least when you only have one lifetime to care about. It's pretty easy to follow with one lifetime.

@ovr ovr requested a review from a team as a code owner August 26, 2024 15:09
@ovr ovr force-pushed the feat/speedup-scan-non-stream branch from d06a7b9 to 21103c1 Compare August 26, 2024 15:12
@ovr ovr merged commit df364be into master Aug 26, 2024
65 checks passed
@ovr ovr deleted the feat/speedup-scan-non-stream branch August 26, 2024 15:57
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.

3 participants