@onekeyfe/react-native-split-bundle-loader 1.1.52 → 1.1.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -135,15 +135,18 @@ class SplitBundleLoaderModule(reactContext: ReactApplicationContext) :
|
|
|
135
135
|
// #19: Try CatalystInstance first (bridge mode), fall back to
|
|
136
136
|
// ReactHost registerSegment if available (bridgeless / new arch).
|
|
137
137
|
val reactContext = reactApplicationContext
|
|
138
|
+
val segStart = System.nanoTime()
|
|
138
139
|
if (reactContext.hasCatalystInstance()) {
|
|
139
140
|
reactContext.catalystInstance.registerSegment(segId, absolutePath)
|
|
140
|
-
|
|
141
|
+
val segMs = (System.nanoTime() - segStart) / 1_000_000.0
|
|
142
|
+
SBLLogger.info("[SplitBundle] segment $segmentKey (id=$segId) registered in ${String.format("%.1f", segMs)}ms")
|
|
141
143
|
promise.resolve(null)
|
|
142
144
|
} else {
|
|
143
145
|
// Bridgeless: try ReactHost via reflection
|
|
144
146
|
val registered = tryRegisterViaBridgeless(segId, absolutePath)
|
|
147
|
+
val segMs = (System.nanoTime() - segStart) / 1_000_000.0
|
|
145
148
|
if (registered) {
|
|
146
|
-
SBLLogger.info("
|
|
149
|
+
SBLLogger.info("[SplitBundle] segment $segmentKey (id=$segId) registered via bridgeless in ${String.format("%.1f", segMs)}ms")
|
|
147
150
|
promise.resolve(null)
|
|
148
151
|
} else {
|
|
149
152
|
promise.reject(
|
package/ios/SplitBundleLoader.mm
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
#import "SplitBundleLoader.h"
|
|
2
2
|
#import "SBLLogger.h"
|
|
3
|
-
#import <
|
|
3
|
+
#import <ReactCommon/RCTHost.h>
|
|
4
|
+
#import <ReactCommon/RCTHost+Internal.h>
|
|
5
|
+
#import <ReactCommon/RCTInstance.h>
|
|
4
6
|
#import <objc/runtime.h>
|
|
5
7
|
#include <jsi/jsi.h>
|
|
6
8
|
|
|
7
|
-
// Bridgeless (New Architecture) support: RCTHost segment registration
|
|
8
|
-
@interface RCTHost (SplitBundle)
|
|
9
|
-
- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path;
|
|
10
|
-
@end
|
|
11
|
-
|
|
12
9
|
@implementation SplitBundleLoader
|
|
13
10
|
|
|
14
11
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
@@ -66,26 +63,16 @@
|
|
|
66
63
|
|
|
67
64
|
// MARK: - Segment registration helper
|
|
68
65
|
|
|
69
|
-
/// Registers a segment with the current runtime
|
|
70
|
-
/// and bridgeless (RCTHost) architectures (#13).
|
|
66
|
+
/// Registers a segment with the current runtime via bridgeless (RCTHost) architecture (#13).
|
|
71
67
|
///
|
|
72
68
|
/// Thread safety (#57): This method is called from the TurboModule (JS thread).
|
|
73
|
-
/// RCTBridge.registerSegmentWithId:path: internally registers the segment with
|
|
74
|
-
/// the Hermes runtime on the JS thread, which is the correct calling context.
|
|
75
69
|
/// No queue dispatch is needed.
|
|
76
70
|
+ (BOOL)registerSegment:(int)segmentId path:(NSString *)path error:(NSError **)outError
|
|
77
71
|
{
|
|
78
|
-
//
|
|
79
|
-
RCTBridge *bridge = [RCTBridge currentBridge];
|
|
80
|
-
if (bridge && [bridge respondsToSelector:@selector(registerSegmentWithId:path:)]) {
|
|
81
|
-
[bridge registerSegmentWithId:@(segmentId) path:path];
|
|
82
|
-
return YES;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Try bridgeless RCTHost via AppDelegate
|
|
72
|
+
// Bridgeless (New Architecture): get RCTHost via AppDelegate
|
|
86
73
|
id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
|
|
87
74
|
if ([appDelegate respondsToSelector:NSSelectorFromString(@"reactHost")]) {
|
|
88
|
-
|
|
75
|
+
RCTHost *host = [appDelegate performSelector:NSSelectorFromString(@"reactHost")];
|
|
89
76
|
if (host && [host respondsToSelector:@selector(registerSegmentWithId:path:)]) {
|
|
90
77
|
[host registerSegmentWithId:@(segmentId) path:path];
|
|
91
78
|
return YES;
|
|
@@ -95,7 +82,7 @@
|
|
|
95
82
|
if (outError) {
|
|
96
83
|
*outError = [NSError errorWithDomain:@"SplitBundleLoader"
|
|
97
84
|
code:1
|
|
98
|
-
userInfo:@{NSLocalizedDescriptionKey: @"
|
|
85
|
+
userInfo:@{NSLocalizedDescriptionKey: @"RCTHost not available for segment registration"}];
|
|
99
86
|
}
|
|
100
87
|
return NO;
|
|
101
88
|
}
|
|
@@ -205,7 +192,7 @@
|
|
|
205
192
|
return;
|
|
206
193
|
}
|
|
207
194
|
|
|
208
|
-
|
|
195
|
+
RCTInstance *instance = object_getIvar(host, ivar);
|
|
209
196
|
if (!instance) {
|
|
210
197
|
[SBLLogger warn:@"loadEntryBundle: _instance is nil"];
|
|
211
198
|
return;
|
|
@@ -218,15 +205,22 @@
|
|
|
218
205
|
}
|
|
219
206
|
|
|
220
207
|
NSString *sourceURL = bundlePath.lastPathComponent ?: bundlePath;
|
|
221
|
-
|
|
208
|
+
CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
|
|
209
|
+
[SBLLogger info:[NSString stringWithFormat:@"[SplitBundle] loadEntryBundle: evaluating %@ (%lu bytes)", sourceURL, (unsigned long)data.length]];
|
|
222
210
|
|
|
223
211
|
[instance callFunctionOnBufferedRuntimeExecutor:^(facebook::jsi::Runtime &runtime) {
|
|
224
212
|
@autoreleasepool {
|
|
213
|
+
CFAbsoluteTime evalStart = CFAbsoluteTimeGetCurrent();
|
|
225
214
|
auto buffer = std::make_shared<facebook::jsi::StringBuffer>(
|
|
226
215
|
std::string(static_cast<const char *>(data.bytes), data.length));
|
|
227
216
|
runtime.evaluateJavaScript(std::move(buffer), [sourceURL UTF8String]);
|
|
217
|
+
double evalMs = (CFAbsoluteTimeGetCurrent() - evalStart) * 1000.0;
|
|
218
|
+
[SBLLogger info:[NSString stringWithFormat:@"[SplitBundle] loadEntryBundle: %@ evaluated in %.1fms", sourceURL, evalMs]];
|
|
228
219
|
}
|
|
229
220
|
}];
|
|
221
|
+
|
|
222
|
+
double totalMs = (CFAbsoluteTimeGetCurrent() - startTime) * 1000.0;
|
|
223
|
+
[SBLLogger info:[NSString stringWithFormat:@"[SplitBundle] loadEntryBundle: %@ dispatched in %.1fms (eval is async)", sourceURL, totalMs]];
|
|
230
224
|
}
|
|
231
225
|
|
|
232
226
|
// MARK: - loadSegment
|
|
@@ -240,6 +234,7 @@
|
|
|
240
234
|
{
|
|
241
235
|
@try {
|
|
242
236
|
int segId = (int)segmentId;
|
|
237
|
+
CFAbsoluteTime segStart = CFAbsoluteTimeGetCurrent();
|
|
243
238
|
|
|
244
239
|
// Path traversal guard (#45)
|
|
245
240
|
if ([relativePath containsString:@".."]) {
|
|
@@ -261,7 +256,8 @@
|
|
|
261
256
|
// Register segment (#13: supports both bridge and bridgeless)
|
|
262
257
|
NSError *regError = nil;
|
|
263
258
|
if ([SplitBundleLoader registerSegment:segId path:absolutePath error:®Error]) {
|
|
264
|
-
|
|
259
|
+
double segMs = (CFAbsoluteTimeGetCurrent() - segStart) * 1000.0;
|
|
260
|
+
[SBLLogger info:[NSString stringWithFormat:@"[SplitBundle] Loaded segment %@ (id=%d) in %.1fms", segmentKey, segId, segMs]];
|
|
265
261
|
resolve(nil);
|
|
266
262
|
} else {
|
|
267
263
|
reject(@"SPLIT_BUNDLE_NO_RUNTIME",
|