mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-06 17:27:54 +08:00
Use JSStringCreateWithUTF8CString and skip NSString decoding when loading the bundle
Summary: public Benchmarking our startup path has shown we spend a lot of time decoding strings (iPhone 4S / iPhone 5): * reading a 2MB JS bundle: 35ms / 15ms * decoding is to an `NSString`: 186ms / 78ms * transforming that to a `JSString`: 29ms / 10ms Instead of going through an `NSString` transformation, we generate a null-terminated bundle (0.1ms / 0.05ms to copy the data) and use `JSStringCreateWithUTF8CString` (121ms / 53ms) to generate the string. That makes decoding 70% faster. Reviewed By: javache Differential Revision: D2541140 fb-gh-sync-id: 09a016b8edfd46a9b62682c76705564d2024e75e
This commit is contained in:
committed by
facebook-github-bot-3
parent
8e2ec64763
commit
4a3857ef1d
@@ -36,8 +36,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
NSString *filePath = scriptURL.path;
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
NSError *error = nil;
|
||||
NSString *rawText = [NSString stringWithContentsOfFile:filePath usedEncoding:NULL error:&error];
|
||||
onComplete(error, rawText);
|
||||
NSData *source = [NSData dataWithContentsOfFile:filePath
|
||||
options:NSDataReadingMappedIfSafe
|
||||
error:&error];
|
||||
onComplete(error, source);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -71,10 +73,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
|
||||
}
|
||||
}
|
||||
NSString *rawText = [[NSString alloc] initWithData:data encoding:encoding];
|
||||
|
||||
// Handle HTTP errors
|
||||
if ([response isKindOfClass:[NSHTTPURLResponse class]] && ((NSHTTPURLResponse *)response).statusCode != 200) {
|
||||
NSString *rawText = [[NSString alloc] initWithData:data encoding:encoding];
|
||||
NSDictionary *userInfo;
|
||||
NSDictionary *errorDetails = RCTJSONParse(rawText, nil);
|
||||
if ([errorDetails isKindOfClass:[NSDictionary class]] &&
|
||||
@@ -101,7 +103,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
onComplete(error, nil);
|
||||
return;
|
||||
}
|
||||
onComplete(nil, rawText);
|
||||
onComplete(nil, data);
|
||||
}];
|
||||
|
||||
[task resume];
|
||||
|
||||
Reference in New Issue
Block a user