swiftlang / swiftlang/swift-corelibs-libdispatch
[SR-9597] DispatchData.copyBytes allocates
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 2.6k
- Forks
- 496
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 3
Description
| Previous ID | SR-9597 |
| Radar | rdar://problem/52529586 |
| Original Reporter | @weissi |
| Type | Bug |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | libdispatch |
| Labels | Bug |
| Assignee | None |
| Priority | Medium |
md5: 63ced7a174d79c5fd0d6f317c1e088e1
Issue Description:
every method I can see to copy bytes out of a DispatchData into some other container of bytes allocates.
DispatchData.copyBytes looks really benign but internally calls (https://github.com/apple/swift-corelibs-libdispatch/blob/9c48a809693b78bd5ad89718c6f9712aaa1cfb1e/src/swift/Data.swift#L221) _copyBytesHelper which calls CDispatch.dispatch_data_apply which needs a closure. That closure has a non-nil context pointer and therefore allocates.
Possible solutions:
-
fix SR-904
-
make enough things inlinable/usableFromInline that we don't actually need to create a proper closure
CC @jckarter, phabouzit (JIRA User), @phausler, @parkera, phabouzit (JIRA User)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/swift/Data.swift around _copyBytesHelper and trace its CDispatch.dispatch_data_apply call. Review the linked SR-904 and the two proposed approaches: resolving the closure allocation or making the relevant code inlinable. Done means DispatchData.copyBytes can copy bytes without allocating.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, swift
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100