-
Notifications
You must be signed in to change notification settings - Fork 235
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
perf: serialize raw results as arrays instead of object #4939
Conversation
quaint/src/connector/ser.rs
Outdated
#[derive(Debug, Copy, Clone, PartialEq, Serialize)] | ||
enum SerializedValueType { | ||
#[serde(rename = "int")] | ||
Int32, | ||
#[serde(rename = "bigint")] | ||
Int64, | ||
#[serde(rename = "float")] | ||
Float, | ||
#[serde(rename = "double")] | ||
Double, | ||
#[serde(rename = "string")] | ||
Text, | ||
#[serde(rename = "enum")] | ||
Enum, | ||
#[serde(rename = "bytes")] | ||
Bytes, | ||
#[serde(rename = "bool")] | ||
Boolean, | ||
#[serde(rename = "char")] | ||
Char, | ||
#[serde(rename = "decimal")] | ||
Numeric, | ||
#[serde(rename = "json")] | ||
Json, | ||
#[serde(rename = "xml")] | ||
Xml, | ||
#[serde(rename = "uuid")] | ||
Uuid, | ||
#[serde(rename = "datetime")] | ||
DateTime, | ||
#[serde(rename = "date")] | ||
Date, | ||
#[serde(rename = "time")] | ||
Time, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to clean that up using this macro:
macro_rules! impl_value_type {
(
$($variant:ident => ($mapped_variant:ident, $rename:expr)),*;
$($array_variant:ident[] => ($mapped_array_variant:ident, $array_rename:expr)),*;
$(($custom_variant:ident, $custom_rename:expr)),*
) => {
#[derive(Debug, Clone, Serialize)]
enum SerializedValueType {
$(
#[serde(rename = $rename)]
$mapped_variant,
)*
$(
#[serde(rename = $array_rename)]
$mapped_array_variant,
)*
$(
#[serde(rename = $custom_rename)]
$custom_variant,
)*
}
impl<'a> From<Value<'a>> for SerializedValueType {
fn from(value: Value<'a>) -> Self {
match &value.typed {
$(
ValueType::$variant(..) => SerializedValueType::$mapped_variant,
)*
ValueType::Array(values) => {
match values {
Some(values) if values.is_empty() => SerializedValueType::UnknownArray,
None => SerializedValueType::UnknownArray,
Some(values) => {
match &values[0].typed {
$(
ValueType::$array_variant(..) => SerializedValueType::$mapped_array_variant,
)*
ValueType::Array(_) | ValueType::EnumArray(_, _) => unreachable!()
}
}
}
}
}
}
}
}
}
impl_value_type! {
Int32 => (Int32, "int"),
Int64 => (Int64, "bigint"),
Float => (Float, "float"),
Double => (Double, "double"),
Text => (String, "string"),
Enum => (Enum, "enum"),
EnumArray => (TextArray, "string-array"),
Bytes => (Bytes, "bytes"),
Boolean => (Boolean, "bool"),
Char => (Char, "char"),
Numeric => (Numeric, "decimal"),
Json => (Json, "json"),
Xml => (Xml, "xml"),
Uuid => (Uuid, "uuid"),
DateTime => ( DateTime, "datetime"),
Date => (Date, "date"),
Time => (Time, "time");
Int32[] => (Int32Array, "int-array"),
Int64[] => (Int64Array, "int64-array"),
Float[] => (FloatArray, "float-array"),
Double[] => (DoubleArray, "double-array"),
Text[] => (TextArray, "string-array"),
Enum[] => (TextArray, "string-array"),
Bytes[] => (BytesArray, "bytes-array"),
Boolean[] => (BooleanArray, "boolean-array"),
Char[] => (CharArray, "char-array"),
Numeric[] => (NumericArray, "numeric-array"),
Json[] => (JsonArray, "json-array"),
Xml[] => (XmlArray, "xml-array"),
Uuid[] => (UuidArray, "uuid-array"),
DateTime[] => (DateTimeArray, "datetime-array"),
Date[] => (DateArray, "date-array"),
Time[] => (TimeArray, "time-array");
(Unknown, "unknown"),
(UnknownArray, "unknown-array")
}
Didn't work well because EnumArray
maps to TextArray
, but so does Text[]
. Also, I need to map Array[]
and EnumArray[]
to unreachable!()
. Lemme know if you find a better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem can be solved through procedural macro, because you can de-duplicate enum variants. This, however, is a bit more effort. I will leave it up to you to decide which approach to go with, I don't feel strongly about it
CodSpeed Performance ReportMerging #4939 will not alter performanceComparing Summary
|
WASM Query Engine file Size
|
quaint/src/connector/ser.rs
Outdated
#[derive(Debug, Copy, Clone, PartialEq, Serialize)] | ||
enum SerializedValueType { | ||
#[serde(rename = "int")] | ||
Int32, | ||
#[serde(rename = "bigint")] | ||
Int64, | ||
#[serde(rename = "float")] | ||
Float, | ||
#[serde(rename = "double")] | ||
Double, | ||
#[serde(rename = "string")] | ||
Text, | ||
#[serde(rename = "enum")] | ||
Enum, | ||
#[serde(rename = "bytes")] | ||
Bytes, | ||
#[serde(rename = "bool")] | ||
Boolean, | ||
#[serde(rename = "char")] | ||
Char, | ||
#[serde(rename = "decimal")] | ||
Numeric, | ||
#[serde(rename = "json")] | ||
Json, | ||
#[serde(rename = "xml")] | ||
Xml, | ||
#[serde(rename = "uuid")] | ||
Uuid, | ||
#[serde(rename = "datetime")] | ||
DateTime, | ||
#[serde(rename = "date")] | ||
Date, | ||
#[serde(rename = "time")] | ||
Time, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem can be solved through procedural macro, because you can de-duplicate enum variants. This, however, is a bit more effort. I will leave it up to you to decide which approach to go with, I don't feel strongly about it
Overview
improves prisma/prisma#23573
closes #1215
Implementation of https://www.notion.so/prismaio/QueryRaw-Performance-Discovery-e65b91e8ac744633aa1a6fe1b85e7341?pvs=4