Page MenuHomePhabricator

[services][blob] Avoid copying data chunks
ClosedPublic

Authored by bartek on Dec 5 2022, 1:27 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, May 2, 12:32 AM
Unknown Object (File)
Apr 3 2024, 4:28 AM
Unknown Object (File)
Apr 3 2024, 4:28 AM
Unknown Object (File)
Apr 3 2024, 4:28 AM
Unknown Object (File)
Apr 3 2024, 4:28 AM
Unknown Object (File)
Apr 3 2024, 4:28 AM
Unknown Object (File)
Apr 3 2024, 4:27 AM
Unknown Object (File)
Apr 3 2024, 4:18 AM
Subscribers

Details

Summary

Resolves ENG-2372
Follow up: https://phab.comm.dev/D5728?id=18851#inline-38316

I could directly use | std::mem::take but my version also maintains initial capacity to avoid reallocatig. I consider this reasonable, as our current chunks will always be between 5-8 MiB (see https://phab.comm.dev/D5703?id=18815#inline-38279)

However, I can just use std::mem::take if requested.

Test Plan
  • Added unit test for this function
  • Service Put endpoint still works as expected

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bartek held this revision as a draft.
bartek published this revision for review.Dec 5 2022, 1:35 AM

Interesting! So the benefit of keeping the capacity is that we don't have to grow the vector after each chunk, right?

Seems like interesting way to go from &mut to an owned version of itself; as long we no longer need to access the chunk after we "reset" it.

I think the name could improved, all I could think of is as_new() or swap_clone() but there's probably a better name out there.

varun added inline comments.
services/blob/src/tools.rs
19 ↗(On Diff #19126)

typo in elements

This revision is now accepted and ready to land.Dec 6 2022, 7:55 PM
  • Fixed typo in comment
  • Renamed the method to take_out() as this name is closer to similiar standard library functions (see the list). Also take_out() is distinguishable from take() which could be confused with iterator.

    I was inspired by the first sentence from this doc:

Takes the value out of this OnceCell, moving it back to an uninitialized state.

This revision was automatically updated to reflect the committed changes.