You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/01/17 20:24:16 UTC
git commit: CB-5299 Cache pbxproj to avoid re-parsing it for each
plugin.
Updated Branches:
refs/heads/master 4a1220678 -> 17a727d9d
CB-5299 Cache pbxproj to avoid re-parsing it for each plugin.
Parsing pbxproj is very slow (~250ms on my machine). It is done for each plugin
that needs to add frameworks to the ios project. This change is a quick and
dirty fix to allow caching the parsed pbxproj object so that it can be reused for
multiple plugins during prepare.
Timings on a test project for cordova prepare ios:
before: 1.623s
after: 0.981s
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/17a727d9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/17a727d9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/17a727d9
Branch: refs/heads/master
Commit: 17a727d9d989ebb0713cc9974ba07700003fe777
Parents: 4a12206
Author: Mark Koudritsky <ka...@gmail.com>
Authored: Thu Jan 16 15:27:58 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jan 17 14:24:08 2014 -0500
----------------------------------------------------------------------
spec/util/config-changes.spec.js | 5 +++--
src/util/config-changes.js | 22 ++++++++++++++++------
2 files changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/17a727d9/spec/util/config-changes.spec.js
----------------------------------------------------------------------
diff --git a/spec/util/config-changes.spec.js b/spec/util/config-changes.spec.js
index 795d825..cbfcc90 100644
--- a/spec/util/config-changes.spec.js
+++ b/spec/util/config-changes.spec.js
@@ -69,7 +69,7 @@ describe('config-changes module', function() {
expect(config.prepare_queue.installed[0].plugin).toEqual('PooPlugin');
});
});
-
+
describe('add_uninstalled_plugin_to_prepare_queue', function() {
beforeEach(function() {
shell.cp('-rf', dummyplugin, plugins_dir);
@@ -305,7 +305,8 @@ describe('config-changes module', function() {
removeFramework:xcode_rm,
writeSync:function(){}
},
- pbx:path.join(temp, 'pbxpath')
+ pbx:path.join(temp, 'pbxpath'),
+ write: function() {}
});
});
it('should call into xcode.addFramework if plugin has <framework> file defined and is ios',function() {
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/17a727d9/src/util/config-changes.js
----------------------------------------------------------------------
diff --git a/src/util/config-changes.js b/src/util/config-changes.js
index 2009f7f..5c212ae 100644
--- a/src/util/config-changes.js
+++ b/src/util/config-changes.js
@@ -290,7 +290,7 @@ module.exports = {
// save
module.exports.save_platform_json(platform_config, plugins_dir, platform);
},
- add_plugin_changes:function(platform, project_dir, plugins_dir, plugin_id, plugin_vars, is_top_level, should_increment) {
+ add_plugin_changes:function(platform, project_dir, plugins_dir, plugin_id, plugin_vars, is_top_level, should_increment, cache) {
var platform_config = module.exports.get_platform_json(plugins_dir, platform);
var plugin_dir = path.join(plugins_dir, plugin_id);
@@ -301,7 +301,11 @@ module.exports = {
// global munge looks at all plugins' changes to config files
var global_munge = platform_config.config_munge;
- var pbxproj, plistObj;
+ var plistObj;
+ // Cache some slow stuff for reuse with multiple plugins.
+ cache = cache || {};
+ var pbxproj = cache.pbxproj;
+
if (platform == 'ios') {
if (config_munge['plugins-plist']) {
var plistfile = glob.sync(path.join(project_dir, '**', '{PhoneGap,Cordova}.plist'));
@@ -314,7 +318,10 @@ module.exports = {
}
}
if (config_munge['framework']) {
- pbxproj = ios_parser.parseProjectFile(project_dir);
+ if (!pbxproj) {
+ // Note, parseProjectFile() is slow, ~250ms on MacBook Pro 2013.
+ cache.pbxproj = pbxproj = ios_parser.parseProjectFile(project_dir);
+ }
}
}
@@ -357,8 +364,7 @@ module.exports = {
// xml_child in this case is whether the framework should use weak or not
var opt = {weak: (xml_child != 'true' ? false : true)};
pbxproj.xcode.addFramework(src, opt);
- // TODO: dont write on every loop eh
- fs.writeFileSync(pbxproj.pbx, pbxproj.xcode.writeSync());
+ pbxproj.needs_write = true;
}
} else {
// this xml child is new, graft it (only if config file exists)
@@ -415,6 +421,9 @@ module.exports = {
// save
module.exports.save_platform_json(platform_config, plugins_dir, platform);
+ if ( pbxproj && pbxproj.needs_write ){
+ pbxproj.write()
+ }
},
process:function(plugins_dir, project_dir, platform) {
checkPlatform(platform);
@@ -426,8 +435,9 @@ module.exports = {
});
// Now handle installation
+ var cache = {};
platform_config.prepare_queue.installed.forEach(function(u) {
- module.exports.add_plugin_changes(platform, project_dir, plugins_dir, u.plugin, u.vars, u.topLevel, true);
+ module.exports.add_plugin_changes(platform, project_dir, plugins_dir, u.plugin, u.vars, u.topLevel, true, cache);
});
platform_config = module.exports.get_platform_json(plugins_dir, platform);