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)
Nov 11 2024, 7:16 PM
Unknown Object (File)
Nov 10 2024, 2:00 PM
Unknown Object (File)
Nov 9 2024, 9:04 AM
Unknown Object (File)
Nov 9 2024, 4:35 AM
Unknown Object (File)
Nov 8 2024, 5:02 AM
Unknown Object (File)
Nov 8 2024, 5:02 AM
Unknown Object (File)
Nov 8 2024, 5:02 AM
Unknown Object (File)
Nov 8 2024, 4:52 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.