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
@discardableResult
public func withUnsafeMutableBytes<Result>(in range: Range<Int>, apply: (UnsafeMutableRawBufferPointer) throws -> Result) rethrows -> Result {
both those functions are generic and not inlineable, that means calling them will always get you an allocation for the generic and probably another one for the closure used (SR-904).
These should definitely be inlineable, otherwise they're pretty much useless 🙁.
For example, running this useless function 1024 times
IIRC, the inlinable part was a deliberate decision at this time to be careful about adding new representations. But this particular case may be important enough to split the function into an inlinable fast path and a non-inlinable slow path, or a non-inlinable part for getting the address but the rest inlinable. (Also, non-escaping closures will soon not require a heap allocation, and generics already shouldn't.)
This seems really unfortunate, but I think a reasonable argument can be made that it is a language problem given the inability to guarantee the scope of a return value which leads us to this pattern in the first place.
Additional Detail from JIRA
md5: 331f4f3551f67dccb54f450d23a70272
Issue Description:
in https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/Data.swift#L122 we find:
in https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/Data.swift#L198 we find:
both those functions are generic and not inlineable, that means calling them will always get you an allocation for the generic and probably another one for the closure used (SR-904).
These should definitely be inlineable, otherwise they're pretty much useless 🙁.
For example, running this useless function 1024 times
gives me these allocations:
which actually looks like 4 allocations per run!
The text was updated successfully, but these errors were encountered: