The seq serialization machinery is a historic artifact from when Go mobile code had to run in a separate process. Now that Go code is running in-process, replace the explicit serialization with direct calls and pass arguments on the stack. The benefits are a much smaller bind runtime, much less garbage (and, in Java, fewer objects with finalizers), less argument copying, and faster cross-language calls. The cost is a more complex generator, because some of the work from the bind runtime is moved to generated code. Generated code now handles conversion between Go and Java/ObjC types, multiple return values and memory management of byte slice and string arguments. To overcome the lack of calling C code between Go packages, all bound packages now end up in the same (fake) package, "gomobile_bind", instead of separate packages (go_<pkgname>). To avoid name clashes, the package name is added as a prefix to generated functions and types. Also, don't copy byte arrays passed to Go, saving call time and allowing read([]byte)-style interfaces to foreign callers (#12113). Finally, add support for nil interfaces and struct pointers to objc. This is a large CL, but most of the changes stem from changing testdata. The full benchcmp output on the CL/20095 benchmarks on my Nexus 5 is reproduced below. Note that the savings for the JavaSlice* benchmarks are skewed because byte slices are no longer copied before passing them to Go. benchmark old ns/op new ns/op delta BenchmarkJavaEmpty 26.0 19.0 -26.92% BenchmarkJavaEmptyDirect 23.0 22.0 -4.35% BenchmarkJavaNoargs 7685 2339 -69.56% BenchmarkJavaNoargsDirect 17405 8041 -53.80% BenchmarkJavaOnearg 26887 2366 -91.20% BenchmarkJavaOneargDirect 34266 7910 -76.92% BenchmarkJavaOneret 38325 2245 -94.14% BenchmarkJavaOneretDirect 46265 7708 -83.34% BenchmarkJavaManyargs 41720 2535 -93.92% BenchmarkJavaManyargsDirect 51026 8373 -83.59% BenchmarkJavaRefjava 38139 21260 -44.26% BenchmarkJavaRefjavaDirect 42706 28150 -34.08% BenchmarkJavaRefgo 34403 6843 -80.11% BenchmarkJavaRefgoDirect 40193 16582 -58.74% BenchmarkJavaStringShort 32366 9323 -71.20% BenchmarkJavaStringShortDirect 41973 19118 -54.45% BenchmarkJavaStringLong 127879 94420 -26.16% BenchmarkJavaStringLongDirect 133776 114760 -14.21% BenchmarkJavaStringShortUnicode 32562 9221 -71.68% BenchmarkJavaStringShortUnicodeDirect 41464 19094 -53.95% BenchmarkJavaStringLongUnicode 131015 89401 -31.76% BenchmarkJavaStringLongUnicodeDirect 134130 90786 -32.31% BenchmarkJavaSliceShort 42462 7538 -82.25% BenchmarkJavaSliceShortDirect 52940 17017 -67.86% BenchmarkJavaSliceLong 138391 8466 -93.88% BenchmarkJavaSliceLongDirect 205804 15666 -92.39% BenchmarkGoEmpty 3.00 3.00 +0.00% BenchmarkGoEmptyDirect 3.00 3.00 +0.00% BenchmarkGoNoarg 40342 13716 -66.00% BenchmarkGoNoargDirect 46691 13569 -70.94% BenchmarkGoOnearg 43529 13757 -68.40% BenchmarkGoOneargDirect 44867 14078 -68.62% BenchmarkGoOneret 45456 13559 -70.17% BenchmarkGoOneretDirect 44694 13442 -69.92% BenchmarkGoRefjava 55111 28071 -49.06% BenchmarkGoRefjavaDirect 60883 26872 -55.86% BenchmarkGoRefgo 57038 29223 -48.77% BenchmarkGoRefgoDirect 56153 27812 -50.47% BenchmarkGoManyargs 67967 17398 -74.40% BenchmarkGoManyargsDirect 60617 16998 -71.96% BenchmarkGoStringShort 57538 22600 -60.72% BenchmarkGoStringShortDirect 52627 22704 -56.86% BenchmarkGoStringLong 128485 52530 -59.12% BenchmarkGoStringLongDirect 138377 52079 -62.36% BenchmarkGoStringShortUnicode 57062 22994 -59.70% BenchmarkGoStringShortUnicodeDirect 62563 22938 -63.34% BenchmarkGoStringLongUnicode 139913 55553 -60.29% BenchmarkGoStringLongUnicodeDirect 150863 57791 -61.69% BenchmarkGoSliceShort 59279 20215 -65.90% BenchmarkGoSliceShortDirect 60160 21136 -64.87% BenchmarkGoSliceLong 411225 301870 -26.59% BenchmarkGoSliceLongDirect 399029 298915 -25.09% Fixes golang/go#12619 Fixes golang/go#12113 Fixes golang/go#13033 Change-Id: I2b45e9e98a1248e3c23a5137f775f7364908bec7 Reviewed-on: https://go-review.googlesource.com/19821 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
156 lines
4.3 KiB
Objective-C
156 lines
4.3 KiB
Objective-C
// Objective-C API for talking to golang.org/x/mobile/bind/objc/testpkg Go package.
|
|
// gobind -lang=objc golang.org/x/mobile/bind/objc/testpkg
|
|
//
|
|
// File is generated by gobind. Do not edit.
|
|
|
|
#ifndef __GoTestpkg_H__
|
|
#define __GoTestpkg_H__
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
@class GoTestpkgNode;
|
|
@class GoTestpkgNullFieldStruct;
|
|
@class GoTestpkgS;
|
|
@class GoTestpkgStructThatStartsWithLetterBeforeZ;
|
|
@protocol GoTestpkgI;
|
|
@class GoTestpkgI;
|
|
@protocol GoTestpkgNullTest;
|
|
@class GoTestpkgNullTest;
|
|
@protocol GoTestpkgZ;
|
|
@class GoTestpkgZ;
|
|
|
|
@interface GoTestpkgNode : NSObject {
|
|
}
|
|
@property(strong, readonly) id _ref;
|
|
|
|
- (id)initWithRef:(id)ref;
|
|
- (NSString*)v;
|
|
- (void)setV:(NSString*)v;
|
|
- (NSString*)err;
|
|
- (void)setErr:(NSString*)v;
|
|
@end
|
|
|
|
@interface GoTestpkgNullFieldStruct : NSObject {
|
|
}
|
|
@property(strong, readonly) id _ref;
|
|
|
|
- (id)initWithRef:(id)ref;
|
|
- (GoTestpkgS*)f;
|
|
- (void)setF:(GoTestpkgS*)v;
|
|
@end
|
|
|
|
@interface GoTestpkgS : NSObject {
|
|
}
|
|
@property(strong, readonly) id _ref;
|
|
|
|
- (id)initWithRef:(id)ref;
|
|
- (double)x;
|
|
- (void)setX:(double)v;
|
|
- (double)y;
|
|
- (void)setY:(double)v;
|
|
- (double)sum;
|
|
- (NSString*)tryTwoStrings:(NSString*)first second:(NSString*)second;
|
|
@end
|
|
|
|
@interface GoTestpkgStructThatStartsWithLetterBeforeZ : NSObject {
|
|
}
|
|
@property(strong, readonly) id _ref;
|
|
|
|
- (id)initWithRef:(id)ref;
|
|
- (id<GoTestpkgZ>)value;
|
|
- (void)setValue:(id<GoTestpkgZ>)v;
|
|
@end
|
|
|
|
@protocol GoTestpkgI
|
|
- (BOOL)error:(BOOL)triggerError error:(NSError**)error;
|
|
- (BOOL)stringError:(NSString*)s ret0_:(NSString**)ret0_ error:(NSError**)error;
|
|
- (int64_t)times:(int32_t)v;
|
|
@end
|
|
|
|
@protocol GoTestpkgNullTest
|
|
- (id<GoTestpkgNullTest>)null;
|
|
@end
|
|
|
|
@protocol GoTestpkgZ
|
|
@end
|
|
|
|
FOUNDATION_EXPORT const BOOL GoTestpkgABool;
|
|
FOUNDATION_EXPORT const double GoTestpkgAFloat;
|
|
FOUNDATION_EXPORT NSString* const GoTestpkgALongString;
|
|
FOUNDATION_EXPORT NSString* const GoTestpkgAString;
|
|
FOUNDATION_EXPORT const int64_t GoTestpkgAnInt;
|
|
FOUNDATION_EXPORT const double GoTestpkgLog2E;
|
|
FOUNDATION_EXPORT const float GoTestpkgMaxFloat32;
|
|
FOUNDATION_EXPORT const double GoTestpkgMaxFloat64;
|
|
FOUNDATION_EXPORT const int32_t GoTestpkgMaxInt32;
|
|
FOUNDATION_EXPORT const int64_t GoTestpkgMaxInt64;
|
|
FOUNDATION_EXPORT const int32_t GoTestpkgMinInt32;
|
|
FOUNDATION_EXPORT const int64_t GoTestpkgMinInt64;
|
|
FOUNDATION_EXPORT const float GoTestpkgSmallestNonzeroFloat32;
|
|
FOUNDATION_EXPORT const double GoTestpkgSmallestNonzeroFloat64;
|
|
|
|
@interface GoTestpkg : NSObject
|
|
+ (int) intVar;
|
|
+ (void) setIntVar:(int)v;
|
|
|
|
+ (id<GoTestpkgI>) interfaceVar;
|
|
+ (void) setInterfaceVar:(id<GoTestpkgI>)v;
|
|
|
|
+ (NSString*) stringVar;
|
|
+ (void) setStringVar:(NSString*)v;
|
|
|
|
+ (GoTestpkgNode*) structVar;
|
|
+ (void) setStructVar:(GoTestpkgNode*)v;
|
|
|
|
@end
|
|
|
|
FOUNDATION_EXPORT NSData* GoTestpkgBytesAppend(NSData* a, NSData* b);
|
|
|
|
FOUNDATION_EXPORT BOOL GoTestpkgCallIError(id<GoTestpkgI> i, BOOL triggerError, NSError** error);
|
|
|
|
FOUNDATION_EXPORT BOOL GoTestpkgCallIStringError(id<GoTestpkgI> i, NSString* s, NSString** ret0_, NSError** error);
|
|
|
|
FOUNDATION_EXPORT double GoTestpkgCallSSum(GoTestpkgS* s);
|
|
|
|
FOUNDATION_EXPORT BOOL GoTestpkgCallWithNull(id<GoTestpkgNullTest> p0, id<GoTestpkgNullTest> nuller);
|
|
|
|
FOUNDATION_EXPORT int GoTestpkgCollectS(int want, int timeoutSec);
|
|
|
|
FOUNDATION_EXPORT NSString* GoTestpkgEcho(NSString* s);
|
|
|
|
FOUNDATION_EXPORT void GoTestpkgGC();
|
|
|
|
FOUNDATION_EXPORT NSString* GoTestpkgHello(NSString* s);
|
|
|
|
FOUNDATION_EXPORT void GoTestpkgHi();
|
|
|
|
FOUNDATION_EXPORT void GoTestpkgInt(int32_t x);
|
|
|
|
FOUNDATION_EXPORT int64_t GoTestpkgMultiply(int32_t idx, int32_t val);
|
|
|
|
FOUNDATION_EXPORT id<GoTestpkgI> GoTestpkgNewI();
|
|
|
|
FOUNDATION_EXPORT GoTestpkgNode* GoTestpkgNewNode(NSString* name);
|
|
|
|
FOUNDATION_EXPORT GoTestpkgNullFieldStruct* GoTestpkgNewNullFieldStruct();
|
|
|
|
FOUNDATION_EXPORT id<GoTestpkgI> GoTestpkgNewNullInterface();
|
|
|
|
FOUNDATION_EXPORT GoTestpkgS* GoTestpkgNewNullStruct();
|
|
|
|
FOUNDATION_EXPORT GoTestpkgS* GoTestpkgNewS(double x, double y);
|
|
|
|
FOUNDATION_EXPORT BOOL GoTestpkgReadIntoByteArray(NSData* s, int* ret0_, NSError** error);
|
|
|
|
FOUNDATION_EXPORT void GoTestpkgRegisterI(int32_t idx, id<GoTestpkgI> i);
|
|
|
|
FOUNDATION_EXPORT BOOL GoTestpkgReturnsError(BOOL b, NSString** ret0_, NSError** error);
|
|
|
|
FOUNDATION_EXPORT NSString* GoTestpkgStringDup(NSString* s);
|
|
|
|
FOUNDATION_EXPORT int64_t GoTestpkgSum(int64_t x, int64_t y);
|
|
|
|
FOUNDATION_EXPORT void GoTestpkgUnregisterI(int32_t idx);
|
|
|
|
#endif
|