You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We deal exclusively with owned database objects like StoredGroup or StoredGroupMessage. We can instead borrow it directly from what the SQLite library returns from the database, avoiding unnecessary allocations. Furthermore, when inserting into the database we can use borrowed variants of our schema to avoid extra allocations before inserting.
There are an abundance of examples around the codebase, but load_identity_updates is a fairly well self-contained example:
/// For the given list of `inbox_id`s get all updates from the network that are newer than the last known `sequence_id`,/// write them in the db, and return the updates#[tracing::instrument(level = "trace", skip_all)]pubasyncfnload_identity_updates<ApiClient:XmtpApi>(api_client:&ApiClientWrapper<ApiClient>,conn:&DbConnection,inbox_ids:&[&str],) -> Result<HashMap<String,Vec<InboxUpdate>>,ClientError>{if inbox_ids.is_empty(){returnOk(HashMap::new());}
tracing::debug!("Fetching identity updates for: {:?}", inbox_ids);let existing_sequence_ids = conn.get_latest_sequence_id(inbox_ids)?;let filters:Vec<GetIdentityUpdatesV2Filter> = inbox_ids
.iter().map(|inbox_id| GetIdentityUpdatesV2Filter{sequence_id: existing_sequence_ids.get(*inbox_id).map(|i| *i asu64),inbox_id: inbox_id.to_string(),}).collect();let updates = api_client.get_identity_updates_v2(filters).await?;let to_store = updates
.iter().flat_map(|(inbox_id, updates)| {
updates.iter().map(|update| StoredIdentityUpdate{inbox_id: inbox_id.clone(),sequence_id: update.sequence_idasi64,server_timestamp_ns: update.server_timestamp_nsasi64,payload: update.update.clone().into(),})}).collect::<Vec<StoredIdentityUpdate>>();
conn.insert_or_ignore_identity_updates(&to_store)?;Ok(updates)}
we could instead insert a StoredIdentityUpdateRef<'_> that borrows inbox_id, and payload
For this one example it doesn't matter much, but multiplied over everywhere we load & store in the codebase, it could have a noticeable effect on perf.
The text was updated successfully, but these errors were encountered:
We deal exclusively with owned database objects like
StoredGroup
orStoredGroupMessage
. We can instead borrow it directly from what the SQLite library returns from the database, avoiding unnecessary allocations. Furthermore, when inserting into the database we can use borrowed variants of our schema to avoid extra allocations before inserting.There are an abundance of examples around the codebase, but
load_identity_updates
is a fairly well self-contained example:we could instead insert a
StoredIdentityUpdateRef<'_>
that borrowsinbox_id
, andpayload
For this one example it doesn't matter much, but multiplied over everywhere we load & store in the codebase, it could have a noticeable effect on perf.
The text was updated successfully, but these errors were encountered: