Bug 275619
| Summary: | Avoid copying of swift return values in Swift-Cpp interop | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Nitin Mahendru <nitinmahendru> |
| Component: | WebCore Misc. | Assignee: | Nitin Mahendru <nitinmahendru> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Other | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Nitin Mahendru
In the existing Swift-Cpp interop interface, when C++ tries to extract values out of swift structs, it generates a Copy.
Even if we declare the same structure in C++ and construct it on swift side with std::optional in it, and then get the value on C++ side, it still generates a copy.
The existing Cpp::makeOptional cannot be changed to take a rvalue reference to avoid the copying as interop does not support rvalue references.
With the current interop features, the best solution for now is to remove optionals and return an empty vector in error scenarios.
This should be a reasonable mitigation as the hot path "should" be success in which case the vector returned actually holds a useful value.
In errors, yes, an empty vector will be returned(adding std::optional was a solution for that problem) but that seems to add extra copies which we
would like to avoid if possible.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Nitin Mahendru
<rdar://problem/129772363>
Nitin Mahendru
Pull request: https://github.com/WebKit/WebKit/pull/29940
EWS
Committed 280218@main (20dee432499d): <https://commits.webkit.org/280218@main>
Reviewed commits have been landed. Closing PR #29940 and removing active labels.