From 4c46936361a55941b6ebc2bbeedee4c393ca6fcb Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Tue, 3 Nov 2015 15:44:25 +0100 Subject: [PATCH 1/3] Stop cloning options for a massive performance boost This seemingly innocent operation is apparently responsible for some serious performance bottlenecks. In testing, I've seen that performance degrades by nearly an order of magnitute per file imported. By not cloning options, this bottleneck goes away, making this plugin significantly faster. On a project with 9 @import rules running this plugin took on average 7 seconds; by removing this clone operation it now takes on average 100ms, with roughly 90% of that time spent in file I/O. --- index.js | 3 +-- package.json | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 1c67d6ab..a68e020a 100755 --- a/index.js +++ b/index.js @@ -5,7 +5,6 @@ var fs = require("fs") var path = require("path") var assign = require("object-assign") -var clone = require("clone") var resolve = require("resolve") var postcss = require("postcss") var helpers = require("postcss-message-helpers") @@ -315,7 +314,7 @@ function readAtImport( result, atRule, parsedAtImport, - clone(options), + options, resolvedFilename, state, media, diff --git a/package.json b/package.json index c16381e1..4bb9d706 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "index.js" ], "dependencies": { - "clone": "^1.0.2", "glob": "^5.0.14", "object-assign": "^4.0.1", "postcss": "^5.0.2", From 2f0c22c795ab29fe6dda2a00cf7e93983b552fc0 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Tue, 3 Nov 2015 16:05:18 +0100 Subject: [PATCH 2/3] Use Object.create to cheaply clone options, allowing mutation By using Object.create, the original options become the prototype of the newly created object, and so any mutation of the options object should just shadow the properties of the prototype. Essentially, this is like cloning by reference, rather than by value, and has almost no performance penalties in this context. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a68e020a..7d6a7df9 100755 --- a/index.js +++ b/index.js @@ -314,7 +314,7 @@ function readAtImport( result, atRule, parsedAtImport, - options, + Object.create(options), resolvedFilename, state, media, From d25897d85e02892b7187aca3674912deaae4c9de Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Tue, 3 Nov 2015 17:10:52 +0100 Subject: [PATCH 3/3] Use `Object.assign` instead of `Object.create` As suggested by @TrySound and @MoOx. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7d6a7df9..01a3c3ce 100755 --- a/index.js +++ b/index.js @@ -314,7 +314,7 @@ function readAtImport( result, atRule, parsedAtImport, - Object.create(options), + Object.assign({}, options), resolvedFilename, state, media,