RESOLVED FIXED275619
Avoid copying of swift return values in Swift-Cpp interop
https://bugs.webkit.org/show_bug.cgi?id=275619
Summary Avoid copying of swift return values in Swift-Cpp interop
Nitin Mahendru
Reported 2024-06-18 09:29:49 PDT
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
Nitin Mahendru
Comment 1 2024-06-18 10:51:30 PDT
Nitin Mahendru
Comment 2 2024-06-18 10:52:49 PDT
EWS
Comment 3 2024-06-20 14:02:42 PDT
Committed 280218@main (20dee432499d): <https://commits.webkit.org/280218@main> Reviewed commits have been landed. Closing PR #29940 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.