Skip to content

Commit ae5de54

Browse files
nicklockwoodfacebook-github-bot-4
authored andcommitted
Reduced module config data
Summary: public We're sending a lot of module config data when the app first starts, and much of this is redundant. UIExplorer current sends 19061 bytes of module config JSON. This diff reduces that to 16104 (15% saving) by stripping modules that have no methods or constants, and removing method types unless method is async. Reviewed By: tadeuzagallo, javache Differential Revision: D2570010 fb-gh-sync-id: 8c0abbd1cdee3264b37a4f52e852008caaffb9c5
1 parent 66717d8 commit ae5de54

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

Libraries/Utilities/MessageQueue.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class MessageQueue {
186186
let moduleNames = Object.keys(localModules);
187187
for (var i = 0, l = moduleNames.length; i < l; i++) {
188188
let moduleName = moduleNames[i];
189-
let methods = localModules[moduleName].methods;
189+
let methods = localModules[moduleName].methods || {};
190190
let moduleID = localModules[moduleName].moduleID;
191191
moduleTable[moduleID] = moduleName;
192192
methodTable[moduleID] = {};
@@ -210,12 +210,16 @@ class MessageQueue {
210210
}
211211

212212
_genModule(module, moduleConfig) {
213-
let methodNames = Object.keys(moduleConfig.methods);
213+
let methods = moduleConfig.methods || {};
214+
let methodNames = Object.keys(methods);
214215
for (var i = 0, l = methodNames.length; i < l; i++) {
215216
let methodName = methodNames[i];
216-
let methodConfig = moduleConfig.methods[methodName];
217+
let methodConfig = methods[methodName];
217218
module[methodName] = this._genMethod(
218-
moduleConfig.moduleID, methodConfig.methodID, methodConfig.type);
219+
moduleConfig.moduleID,
220+
methodConfig.methodID,
221+
methodConfig.type || MethodTypes.remote
222+
);
219223
}
220224
Object.assign(module, moduleConfig.constants);
221225
return module;
@@ -260,7 +264,7 @@ class MessageQueue {
260264

261265
}
262266

263-
function createErrorFromErrorData(errorData: ErrorData): Error {
267+
function createErrorFromErrorData(errorData: {message: string}): Error {
264268
var {
265269
message,
266270
...extraErrorInfo,

React/Base/RCTBatchedBridge.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ - (NSString *)moduleConfig
310310
{
311311
NSMutableDictionary *config = [NSMutableDictionary new];
312312
for (RCTModuleData *moduleData in _moduleDataByID) {
313-
config[moduleData.name] = moduleData.config;
313+
NSDictionary *moduleConfig = moduleData.config;
314+
if (moduleConfig) {
315+
config[moduleData.name] = moduleConfig;
316+
}
314317
if ([moduleData.instance conformsToProtocol:@protocol(RCTFrameUpdateObserver)]) {
315318
[_frameUpdateObservers addObject:moduleData];
316319

React/Base/RCTModuleData.m

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ - (NSArray *)methods
8181

8282
- (NSDictionary *)config
8383
{
84+
if (_constants.count == 0 && self.methods.count == 0) {
85+
return nil; // Nothing to export
86+
}
87+
8488
NSMutableDictionary *config = [NSMutableDictionary new];
8589
config[@"moduleID"] = _moduleID;
8690

@@ -90,12 +94,20 @@ - (NSDictionary *)config
9094

9195
NSMutableDictionary *methodconfig = [NSMutableDictionary new];
9296
[self.methods enumerateObjectsUsingBlock:^(id<RCTBridgeMethod> method, NSUInteger idx, __unused BOOL *stop) {
93-
methodconfig[method.JSMethodName] = @{
94-
@"methodID": @(idx),
95-
@"type": method.functionType == RCTFunctionTypePromise ? @"remoteAsync" : @"remote",
96-
};
97+
if (method.functionType == RCTFunctionTypePromise) {
98+
methodconfig[method.JSMethodName] = @{
99+
@"methodID": @(idx),
100+
@"type": @"remoteAsync",
101+
};
102+
} else {
103+
methodconfig[method.JSMethodName] = @{
104+
@"methodID": @(idx),
105+
};
106+
}
97107
}];
98-
config[@"methods"] = [methodconfig copy];
108+
if (methodconfig.count) {
109+
config[@"methods"] = [methodconfig copy];
110+
}
99111

100112
return [config copy];
101113
}

0 commit comments

Comments
 (0)