Skip to content

Commit 9c8d67d

Browse files
Benchmarks: optional-return cases and runner tweaks (#529)
* Benchmarks: add optional-return cases and improve runner * Benchmarks: pass iterations without globals * Run ./Utilities/bridge-js-generate.sh --------- Co-authored-by: Krzysztof Rodak <krodak.konta@gmail.com>
1 parent 28d3db1 commit 9c8d67d

File tree

4 files changed

+402
-9
lines changed

4 files changed

+402
-9
lines changed

Benchmarks/Sources/Benchmarks.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ enum ComplexResult {
111111
}
112112
}
113113

114+
@JS class OptionalReturnRoundtrip {
115+
@JS init() {}
116+
117+
@JS func makeIntSome() -> Int? { 42 }
118+
@JS func makeIntNone() -> Int? { nil }
119+
120+
@JS func makeBoolSome() -> Bool? { true }
121+
@JS func makeBoolNone() -> Bool? { nil }
122+
123+
@JS func makeDoubleSome() -> Double? { 0.5 }
124+
@JS func makeDoubleNone() -> Double? { nil }
125+
126+
@JS func makeStringSome() -> String? { "Hello, world" }
127+
@JS func makeStringNone() -> String? { nil }
128+
}
129+
114130
// MARK: - Struct Performance Tests
115131

116132
@JS struct SimpleStruct {

Benchmarks/Sources/Generated/BridgeJS.swift

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,130 @@ fileprivate func _bjs_StringRoundtrip_wrap(_ pointer: UnsafeMutableRawPointer) -
839839
}
840840
#endif
841841

842+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_init")
843+
@_cdecl("bjs_OptionalReturnRoundtrip_init")
844+
public func _bjs_OptionalReturnRoundtrip_init() -> UnsafeMutableRawPointer {
845+
#if arch(wasm32)
846+
let ret = OptionalReturnRoundtrip()
847+
return ret.bridgeJSLowerReturn()
848+
#else
849+
fatalError("Only available on WebAssembly")
850+
#endif
851+
}
852+
853+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeIntSome")
854+
@_cdecl("bjs_OptionalReturnRoundtrip_makeIntSome")
855+
public func _bjs_OptionalReturnRoundtrip_makeIntSome(_ _self: UnsafeMutableRawPointer) -> Void {
856+
#if arch(wasm32)
857+
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeIntSome()
858+
return ret.bridgeJSLowerReturn()
859+
#else
860+
fatalError("Only available on WebAssembly")
861+
#endif
862+
}
863+
864+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeIntNone")
865+
@_cdecl("bjs_OptionalReturnRoundtrip_makeIntNone")
866+
public func _bjs_OptionalReturnRoundtrip_makeIntNone(_ _self: UnsafeMutableRawPointer) -> Void {
867+
#if arch(wasm32)
868+
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeIntNone()
869+
return ret.bridgeJSLowerReturn()
870+
#else
871+
fatalError("Only available on WebAssembly")
872+
#endif
873+
}
874+
875+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeBoolSome")
876+
@_cdecl("bjs_OptionalReturnRoundtrip_makeBoolSome")
877+
public func _bjs_OptionalReturnRoundtrip_makeBoolSome(_ _self: UnsafeMutableRawPointer) -> Void {
878+
#if arch(wasm32)
879+
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeBoolSome()
880+
return ret.bridgeJSLowerReturn()
881+
#else
882+
fatalError("Only available on WebAssembly")
883+
#endif
884+
}
885+
886+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeBoolNone")
887+
@_cdecl("bjs_OptionalReturnRoundtrip_makeBoolNone")
888+
public func _bjs_OptionalReturnRoundtrip_makeBoolNone(_ _self: UnsafeMutableRawPointer) -> Void {
889+
#if arch(wasm32)
890+
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeBoolNone()
891+
return ret.bridgeJSLowerReturn()
892+
#else
893+
fatalError("Only available on WebAssembly")
894+
#endif
895+
}
896+
897+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeDoubleSome")
898+
@_cdecl("bjs_OptionalReturnRoundtrip_makeDoubleSome")
899+
public func _bjs_OptionalReturnRoundtrip_makeDoubleSome(_ _self: UnsafeMutableRawPointer) -> Void {
900+
#if arch(wasm32)
901+
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeDoubleSome()
902+
return ret.bridgeJSLowerReturn()
903+
#else
904+
fatalError("Only available on WebAssembly")
905+
#endif
906+
}
907+
908+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeDoubleNone")
909+
@_cdecl("bjs_OptionalReturnRoundtrip_makeDoubleNone")
910+
public func _bjs_OptionalReturnRoundtrip_makeDoubleNone(_ _self: UnsafeMutableRawPointer) -> Void {
911+
#if arch(wasm32)
912+
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeDoubleNone()
913+
return ret.bridgeJSLowerReturn()
914+
#else
915+
fatalError("Only available on WebAssembly")
916+
#endif
917+
}
918+
919+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeStringSome")
920+
@_cdecl("bjs_OptionalReturnRoundtrip_makeStringSome")
921+
public func _bjs_OptionalReturnRoundtrip_makeStringSome(_ _self: UnsafeMutableRawPointer) -> Void {
922+
#if arch(wasm32)
923+
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeStringSome()
924+
return ret.bridgeJSLowerReturn()
925+
#else
926+
fatalError("Only available on WebAssembly")
927+
#endif
928+
}
929+
930+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeStringNone")
931+
@_cdecl("bjs_OptionalReturnRoundtrip_makeStringNone")
932+
public func _bjs_OptionalReturnRoundtrip_makeStringNone(_ _self: UnsafeMutableRawPointer) -> Void {
933+
#if arch(wasm32)
934+
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeStringNone()
935+
return ret.bridgeJSLowerReturn()
936+
#else
937+
fatalError("Only available on WebAssembly")
938+
#endif
939+
}
940+
941+
@_expose(wasm, "bjs_OptionalReturnRoundtrip_deinit")
942+
@_cdecl("bjs_OptionalReturnRoundtrip_deinit")
943+
public func _bjs_OptionalReturnRoundtrip_deinit(_ pointer: UnsafeMutableRawPointer) -> Void {
944+
#if arch(wasm32)
945+
Unmanaged<OptionalReturnRoundtrip>.fromOpaque(pointer).release()
946+
#else
947+
fatalError("Only available on WebAssembly")
948+
#endif
949+
}
950+
951+
extension OptionalReturnRoundtrip: ConvertibleToJSValue, _BridgedSwiftHeapObject {
952+
var jsValue: JSValue {
953+
return .object(JSObject(id: UInt32(bitPattern: _bjs_OptionalReturnRoundtrip_wrap(Unmanaged.passRetained(self).toOpaque()))))
954+
}
955+
}
956+
957+
#if arch(wasm32)
958+
@_extern(wasm, module: "Benchmarks", name: "bjs_OptionalReturnRoundtrip_wrap")
959+
fileprivate func _bjs_OptionalReturnRoundtrip_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32
960+
#else
961+
fileprivate func _bjs_OptionalReturnRoundtrip_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 {
962+
fatalError("Only available on WebAssembly")
963+
}
964+
#endif
965+
842966
@_expose(wasm, "bjs_StructRoundtrip_init")
843967
@_cdecl("bjs_StructRoundtrip_init")
844968
public func _bjs_StructRoundtrip_init() -> UnsafeMutableRawPointer {

Benchmarks/Sources/Generated/JavaScript/BridgeJS.json

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,194 @@
424424
],
425425
"swiftCallName" : "StringRoundtrip"
426426
},
427+
{
428+
"constructor" : {
429+
"abiName" : "bjs_OptionalReturnRoundtrip_init",
430+
"effects" : {
431+
"isAsync" : false,
432+
"isStatic" : false,
433+
"isThrows" : false
434+
},
435+
"parameters" : [
436+
437+
]
438+
},
439+
"methods" : [
440+
{
441+
"abiName" : "bjs_OptionalReturnRoundtrip_makeIntSome",
442+
"effects" : {
443+
"isAsync" : false,
444+
"isStatic" : false,
445+
"isThrows" : false
446+
},
447+
"name" : "makeIntSome",
448+
"parameters" : [
449+
450+
],
451+
"returnType" : {
452+
"optional" : {
453+
"_0" : {
454+
"int" : {
455+
456+
}
457+
}
458+
}
459+
}
460+
},
461+
{
462+
"abiName" : "bjs_OptionalReturnRoundtrip_makeIntNone",
463+
"effects" : {
464+
"isAsync" : false,
465+
"isStatic" : false,
466+
"isThrows" : false
467+
},
468+
"name" : "makeIntNone",
469+
"parameters" : [
470+
471+
],
472+
"returnType" : {
473+
"optional" : {
474+
"_0" : {
475+
"int" : {
476+
477+
}
478+
}
479+
}
480+
}
481+
},
482+
{
483+
"abiName" : "bjs_OptionalReturnRoundtrip_makeBoolSome",
484+
"effects" : {
485+
"isAsync" : false,
486+
"isStatic" : false,
487+
"isThrows" : false
488+
},
489+
"name" : "makeBoolSome",
490+
"parameters" : [
491+
492+
],
493+
"returnType" : {
494+
"optional" : {
495+
"_0" : {
496+
"bool" : {
497+
498+
}
499+
}
500+
}
501+
}
502+
},
503+
{
504+
"abiName" : "bjs_OptionalReturnRoundtrip_makeBoolNone",
505+
"effects" : {
506+
"isAsync" : false,
507+
"isStatic" : false,
508+
"isThrows" : false
509+
},
510+
"name" : "makeBoolNone",
511+
"parameters" : [
512+
513+
],
514+
"returnType" : {
515+
"optional" : {
516+
"_0" : {
517+
"bool" : {
518+
519+
}
520+
}
521+
}
522+
}
523+
},
524+
{
525+
"abiName" : "bjs_OptionalReturnRoundtrip_makeDoubleSome",
526+
"effects" : {
527+
"isAsync" : false,
528+
"isStatic" : false,
529+
"isThrows" : false
530+
},
531+
"name" : "makeDoubleSome",
532+
"parameters" : [
533+
534+
],
535+
"returnType" : {
536+
"optional" : {
537+
"_0" : {
538+
"double" : {
539+
540+
}
541+
}
542+
}
543+
}
544+
},
545+
{
546+
"abiName" : "bjs_OptionalReturnRoundtrip_makeDoubleNone",
547+
"effects" : {
548+
"isAsync" : false,
549+
"isStatic" : false,
550+
"isThrows" : false
551+
},
552+
"name" : "makeDoubleNone",
553+
"parameters" : [
554+
555+
],
556+
"returnType" : {
557+
"optional" : {
558+
"_0" : {
559+
"double" : {
560+
561+
}
562+
}
563+
}
564+
}
565+
},
566+
{
567+
"abiName" : "bjs_OptionalReturnRoundtrip_makeStringSome",
568+
"effects" : {
569+
"isAsync" : false,
570+
"isStatic" : false,
571+
"isThrows" : false
572+
},
573+
"name" : "makeStringSome",
574+
"parameters" : [
575+
576+
],
577+
"returnType" : {
578+
"optional" : {
579+
"_0" : {
580+
"string" : {
581+
582+
}
583+
}
584+
}
585+
}
586+
},
587+
{
588+
"abiName" : "bjs_OptionalReturnRoundtrip_makeStringNone",
589+
"effects" : {
590+
"isAsync" : false,
591+
"isStatic" : false,
592+
"isThrows" : false
593+
},
594+
"name" : "makeStringNone",
595+
"parameters" : [
596+
597+
],
598+
"returnType" : {
599+
"optional" : {
600+
"_0" : {
601+
"string" : {
602+
603+
}
604+
}
605+
}
606+
}
607+
}
608+
],
609+
"name" : "OptionalReturnRoundtrip",
610+
"properties" : [
611+
612+
],
613+
"swiftCallName" : "OptionalReturnRoundtrip"
614+
},
427615
{
428616
"constructor" : {
429617
"abiName" : "bjs_StructRoundtrip_init",

0 commit comments

Comments
 (0)