<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>275619</bug_id>
          
          <creation_ts>2024-06-18 09:29:49 -0700</creation_ts>
          <short_desc>Avoid copying of swift return values in Swift-Cpp interop</short_desc>
          <delta_ts>2024-06-20 14:02:44 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Nitin Mahendru">nitinmahendru</reporter>
          <assigned_to name="Nitin Mahendru">nitinmahendru</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2041891</commentid>
    <comment_count>0</comment_count>
    <who name="Nitin Mahendru">nitinmahendru</who>
    <bug_when>2024-06-18 09:29:49 -0700</bug_when>
    <thetext>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 &quot;should&quot; 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2041910</commentid>
    <comment_count>1</comment_count>
    <who name="Nitin Mahendru">nitinmahendru</who>
    <bug_when>2024-06-18 10:51:30 -0700</bug_when>
    <thetext>&lt;rdar://problem/129772363&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2041911</commentid>
    <comment_count>2</comment_count>
    <who name="Nitin Mahendru">nitinmahendru</who>
    <bug_when>2024-06-18 10:52:49 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/29940</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2042307</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-06-20 14:02:42 -0700</bug_when>
    <thetext>Committed 280218@main (20dee432499d): &lt;https://commits.webkit.org/280218@main&gt;

Reviewed commits have been landed. Closing PR #29940 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>