Skip to content

Commit

Permalink
Move a Box::pin to drastically reduce the size of a future
Browse files Browse the repository at this point in the history
This reduces the size of the `try_get_with_by_ref()` future from 15560 bytes to
824 bytes.
  • Loading branch information
jwodder committed Jul 12, 2024
1 parent 8c3d884 commit b13959a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/dandi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ impl DandiClient {
key.push('/');
}
let prefix = PureDirPath::try_from(key).map_err(ZarrToS3Error::BadS3Key)?;
// Box large future:
match Box::pin(self.s3clients.try_get_with_by_ref(&bucket_spec, async {
bucket_spec.clone().into_s3client().await.map(Arc::new)
}))
.await
// Box the future passed to moka in order to minimize the size of the
// moka future (cf. <https://github.com/moka-rs/moka/issues/212>):
match self
.s3clients
.try_get_with_by_ref(
&bucket_spec,
Box::pin(async { bucket_spec.clone().into_s3client().await.map(Arc::new) }),
)
.await

Check warning on line 76 in src/dandi/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/dandi/mod.rs#L70-L76

Added lines #L70 - L76 were not covered by tests
{
Ok(client) => Ok(client.with_prefix(prefix)),
Err(source) => Err(ZarrToS3Error::LocateBucket {
Expand Down

0 comments on commit b13959a

Please sign in to comment.