From 2a7a6a6c15f82ccc802b3897fcc2f9643d129973 Mon Sep 17 00:00:00 2001 From: Scott Sanders Date: Sun, 1 Jan 2012 12:18:50 -0800 Subject: [PATCH] caching compiles increases speed: coffeekup 62x, ejs >5x, haml 12x, jade ~6x, jqtpl minor, mu2 4x, swig ~1.4x, templ8 ~20x, whiskers >7x, also move up to the latest versions as of Jan 1, 2012 --- lib/languages/coffeekup.js | 4 +++- lib/languages/ejs.js | 4 +++- lib/languages/haml.js | 4 +++- lib/languages/jade.js | 4 +++- lib/languages/jqtpl.js | 4 +++- lib/languages/mu2.js | 16 ++++++++++------ lib/languages/swig.js | 6 ++++-- lib/languages/templ8.js | 4 +++- lib/languages/whiskers.js | 4 +++- package.json | 14 +++++++------- 10 files changed, 42 insertions(+), 22 deletions(-) diff --git a/lib/languages/coffeekup.js b/lib/languages/coffeekup.js index 5a3ca7e..2e0b492 100644 --- a/lib/languages/coffeekup.js +++ b/lib/languages/coffeekup.js @@ -14,7 +14,9 @@ var coffeekup = require('coffeekup'), tpl = {}; exports.compile = function (type, callback) { - tpl[type] = coffeekup.compile(files[type]); + if (!tpl[type]) { + tpl[type] = coffeekup.compile(files[type]); + } callback(); }; diff --git a/lib/languages/ejs.js b/lib/languages/ejs.js index 2bf15fd..0d2624d 100644 --- a/lib/languages/ejs.js +++ b/lib/languages/ejs.js @@ -14,7 +14,9 @@ var ejs = require('ejs'), tpl = {}; exports.compile = function (type, callback) { - tpl[type] = ejs.compile(files[type]); + if (!tpl[type]) { + tpl[type] = ejs.compile(files[type]); + } callback(); }; diff --git a/lib/languages/haml.js b/lib/languages/haml.js index 34243e0..0f16755 100644 --- a/lib/languages/haml.js +++ b/lib/languages/haml.js @@ -14,7 +14,9 @@ var Haml = require('haml'), tpl = {}; exports.compile = function (type, callback) { - tpl[type] = Haml(files[type], {customEscape: "html_escape"}); + if (!tpl[type]) { + tpl[type] = Haml(files[type], {customEscape: "html_escape"}); + } callback(); }; diff --git a/lib/languages/jade.js b/lib/languages/jade.js index 15a0db7..a8b2c9a 100644 --- a/lib/languages/jade.js +++ b/lib/languages/jade.js @@ -14,7 +14,9 @@ var jade = require('jade'), tpl = {}; exports.compile = function (type, callback) { - tpl[type] = jade.compile(files[type]); + if (!tpl[type]) { + tpl[type] = jade.compile(files[type]); + } callback(); }; diff --git a/lib/languages/jqtpl.js b/lib/languages/jqtpl.js index 79a1dd4..a7b9b3d 100644 --- a/lib/languages/jqtpl.js +++ b/lib/languages/jqtpl.js @@ -14,7 +14,9 @@ var jqtpl = require('jqtpl'), tpl = {}; exports.compile = function (type, callback) { - tpl[type] = jqtpl.template(type, files[type]); + if (!tpl[type]) { + tpl[type] = jqtpl.template(type, files[type]); + } callback(); }; diff --git a/lib/languages/mu2.js b/lib/languages/mu2.js index 6153abb..d2fc6d0 100644 --- a/lib/languages/mu2.js +++ b/lib/languages/mu2.js @@ -23,13 +23,17 @@ var mu = require('mu2'), tpl = {}; exports.compile = function (type, callback) { - mu.compileText(type, files[type], function (error, compiled) { - if (error) { - console.log(error); - } - tpl[type] = compiled; + if (!tpl[type]) { + mu.compileText(type, files[type], function (error, compiled) { + if (error) { + console.log(error); + } + tpl[type] = compiled; + callback(); + }); + } else { callback(); - }); + } }; exports.render = function (type, callback) { diff --git a/lib/languages/swig.js b/lib/languages/swig.js index 37b1318..7c0f283 100644 --- a/lib/languages/swig.js +++ b/lib/languages/swig.js @@ -18,11 +18,13 @@ swig.init({ }); exports.compile = function (type, callback) { - tpl[type] = swig.fromString(files[type]); + if (!tpl[type]) { + tpl[type] = swig.compile(files[type]); + } callback(); }; exports.render = function (type, callback) { - tpl[type].render(data); + tpl[type](data); callback(); }; diff --git a/lib/languages/templ8.js b/lib/languages/templ8.js index 81785a4..74d72d8 100644 --- a/lib/languages/templ8.js +++ b/lib/languages/templ8.js @@ -15,7 +15,9 @@ var Templ8 = require('Templ8'), exports.compile = function (type, callback) { - tpl[type] = new Templ8(files[type], { compiled: true }); + if (!tpl[type]) { + tpl[type] = new Templ8(files[type], { compiled: true }); + } callback(); }; diff --git a/lib/languages/whiskers.js b/lib/languages/whiskers.js index 754675d..756e95e 100644 --- a/lib/languages/whiskers.js +++ b/lib/languages/whiskers.js @@ -14,7 +14,9 @@ var whiskers = require('whiskers'), tpl = {}; exports.compile = function (type, callback) { - tpl[type] = whiskers.compile(files[type]); + if (!tpl[type]) { + tpl[type] = whiskers.compile(files[type]); + } callback(); }; diff --git a/package.json b/package.json index 69c9008..a4182f9 100644 --- a/package.json +++ b/package.json @@ -7,16 +7,16 @@ "homepage": "http://paularmstrong.github.com/node-templates/", "author": "Paul Armstrong ", "dependencies": { - "nopt": ">=1.0.8", - "bench": ">=0.3.2", + "nopt": ">=1.0.10", + "bench": ">=0.3.4", "nodelint": "0.5.2", - "underscore": ">=1.1.7", + "underscore": ">=1.2.3", "coffeekup": "0.3.0", - "ejs": "0.4.2", - "hamljs": "0.5.1", + "ejs": "0.6.1", + "hamljs": "0.5.2", "haml": "0.4.2", - "jade": "0.16.0", - "jqtpl": "1.0.6", + "jade": "0.20.0", + "jqtpl": "1.0.7", "mu2": "0.5.3", "swig": "0.7.0", "Templ8": "0.2.1",