-
|
I have a struct, roughly: #[derive(Queryable, Identifiable, Insertable, AsChangeset, Debug)]
#[changeset_options(treat_none_as_null = "true")]
#[table_name = "people"]
pub struct Person {
pub id: Uuid,
pub hash: String,
pub first_name: Option<String>,
pub middle_name: Option<String>,
pub last_name: Option<String>,
pub email: Option<String>,
pub roles: Option<Vec<Role>>,
pub graduation_year: Option<i32>,
pub grade_levels: Option<Vec<String>>,
pub display_name: Option<String>,
pub picture_url: Option<String>,
pub phone: Option<String>,
pub locale: Option<String>,
pub time_zone: Option<String>,
pub country_of_birth: Option<String>,
pub state_of_birth: Option<String>,
pub city_of_birth: Option<String>,
pub ethnicity: Option<String>,
pub races: Option<Vec<Race>>,
pub birthday: Option<DateTime<Utc>>,
pub gender: Option<Gender>,
pub residence_status: Option<String>,
pub language: Option<String>,
pub identifiers: EntityIdentifiers,
pub properties: serde_json::Value,
pub parent_id: Uuid,
pub parent_org_id: Uuid,
pub source_id: Uuid,
pub destination_id: Uuid,
}The biggest take-away from this struct is its size, mainly. I am creating anywhere between 5000 and 1m unique structs of this kind, and attempting to insert them: fn batch_insert(
conn: &diesel::PgConnection,
entities: Vec<Person>,
) -> Result<(), diesel::result::Error> {
diesel::insert_into(entity::people::table)
.values(entity)
.execute(conn)?;
Ok(())
}This operation takes an absolutely unwieldy amount of time, roughly 100ms for a single entity, or roughly 1.5 minutes per 1k items. From my analysis, almost none of this time is actually spent in postgres: Using a debugger revealed it to be in the generation of the statement, specifically here. I have tried a variety of things, including adding the QueryID derive macro to the struct, ensuring that the entity being inserted is owned (and inversely explicitly borrowing it), splitting the operation into batches (but the time spent seems to be roughly linear), etc. to no avail. Am I missing something obvious? Is there a way to speed this up? In typescript, doing a similar operation on a similar JSON object using This is on both the 2018 and 2021 edition, using diesel 1.4.8. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
This is likely caused by #2071, assuming that one of the not by default supported types is a custom type impl. Its already fixed on the master, so you can try that or you can try to provide a oid known at compile time for your custom type definitions. |
Beta Was this translation helpful? Give feedback.
This is likely caused by #2071, assuming that one of the not by default supported types is a custom type impl. Its already fixed on the master, so you can try that or you can try to provide a oid known at compile time for your custom type definitions.