swift-nio icon indicating copy to clipboard operation
swift-nio copied to clipboard

ByteBuffer: one fewer allocs to go to Data

Open weissi opened this issue 3 years ago • 1 comments

Motivation:

When getting a Data from a ByteBuffer we currently allocate twice (__DataStorage) and the closure for Data.Deallocator.

Modifications:

We can optimise that by making the closure capture exactly one AnyObject which is already a reference counted object. The compiler realises that (on Linux) and saves us an alloc.

Thanks @lukasa for the suggestion here: https://github.com/apple/swift-nio/pull/1836#issuecomment-830044155

Result:

Fewer allocs.

weissi avatar Apr 30 '21 14:04 weissi

We should resurrect this

weissi avatar Aug 17 '23 20:08 weissi