From 261acbde88ca060f67161ef210426314bd4da5d4 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Thu, 22 Aug 2013 18:06:16 -0700 Subject: [PATCH] add .query memoization for ultimate hello world benchmarks --- benchmarks/middleware.js | 1 - benchmarks/run | 2 +- lib/context.js | 6 ++++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/benchmarks/middleware.js b/benchmarks/middleware.js index cce3276..300b892 100644 --- a/benchmarks/middleware.js +++ b/benchmarks/middleware.js @@ -11,7 +11,6 @@ console.log(' %s middleware', n); while (n--) { app.use(function(next){ return function *(){ - var p = this.path; yield next; } }); diff --git a/benchmarks/run b/benchmarks/run index d1ad6d4..862acb1 100755 --- a/benchmarks/run +++ b/benchmarks/run @@ -6,7 +6,7 @@ pid=$! sleep 2 -wrk http://localhost:3000/ \ +wrk 'http://localhost:3000/?foo[bar]=baz' \ -r 2000 \ -c 50 \ -t 4 \ diff --git a/lib/context.js b/lib/context.js index cf442bf..4429d1d 100644 --- a/lib/context.js +++ b/lib/context.js @@ -142,7 +142,7 @@ module.exports = { */ get path() { - var c = this._pc = this._pc || {}; + var c = this._pathcache = this._pathcache || {}; return c[this.url] || (c[this.url] = parse(this.url).pathname); }, @@ -169,7 +169,9 @@ module.exports = { get query() { var str = this.querystring; if (!str) return {}; - return qs.parse(str); + + var c = this._querycache = this._querycache || {}; + return c[str] || (c[str] = qs.parse(str)); }, /**