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
Eagerly move attachable values to the heap. (#809)
This PR modifies `Test.Attachment.init(...)` so that, if the attachable
value passed to it is of a large or non-bitwise-copyable value type, we
store it in a heap-allocated container object.
Why do we want to do this? Attachable values have arbitrary types we
don't really know anything about, and may be very expensive to copy if
they are large or if they contain many references to other objects.
Since attachments are sendable and need to pass through many layers in
the system, the cost of making copies for these attachable values can
add up quickly. So, instead of copying them repeatedly, if we store them
in a refcounted container and pass _that_ value around, we only infer a
single copy cost.
There are four modes for attachable value storage after this PR:
```mermaid
flowchart TB;
S@{ shape: diam, label: "Sendable?" };
C@{ shape: diam, label: "Copyable?" };
AO@{ shape: diam, label: "AnyObject?" };
BC@{ shape: diam, label: "BitwiseCopyable (POD)?" };
SMOL@{ shape: diam, label: "Fits in an existential box?" };
MO@{ shape: das, label: "In a heap-allocated box\n(eagerly serialized)" };
EX@{ shape: das, label: "Inline in an existential box" };
H@{ shape: das, label: "In a heap-allocated box" };
RC@{ shape: das, label: "Directly on the heap" };
S-- Yes ---C
C-- Yes ---AO
AO-- Yes ---RC
AO-- No ---BC
BC-- Yes ---SMOL
BC-- No ---H
SMOL-- Yes ---EX
SMOL-- No ---H
C-- No ---MO
S-- No ---MO
```
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
0 commit comments