From 27b3e22c27f6921f1adc77af746f7b8788bbea4c Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Fri, 18 Nov 2016 18:03:11 +0100 Subject: [PATCH 1/2] Improve Atom startup time Before this change, activation was done on Atom startup, whether or not you actually had any CoffeeScript files open. With this change in place, we postpone activation until the Atom CoffeeScript grammar's first use. This improves startup time of my Atom by about 29ms, thus fixing one of the top startup time offenders according to TimeCop. For some frame of reference, I have 87 packages installed, and Timecop lists all packages with startup times above 5ms. --- package.json | 1 + spec/linter-coffeelint-spec.js | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7d84232..53ec620 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "engines": { "atom": ">=1.0.0 <2.0.0" }, + "activationHooks": ["language-coffee-script:grammar-used"], "package-deps": [ "linter" ], diff --git a/spec/linter-coffeelint-spec.js b/spec/linter-coffeelint-spec.js index fce6492..7047439 100644 --- a/spec/linter-coffeelint-spec.js +++ b/spec/linter-coffeelint-spec.js @@ -9,12 +9,22 @@ const lint = require('../lib/init.coffee').provideLinter().lint; describe('The CoffeeLint provider for Linter', () => { describe('works with CoffeeScript files and', () => { beforeEach(() => { + // This whole beforeEach function is inspired by: + // https://github.com/AtomLinter/linter-jscs/pull/295/files + // + // See also: + // https://discuss.atom.io/t/activationhooks-break-unit-tests/36028/8 + const activationPromise = + atom.packages.activatePackage('linter-coffeelint'); + waitsForPromise(() => - Promise.all([ - atom.packages.activatePackage('linter-coffeelint'), - atom.packages.activatePackage('language-coffee-script'), - ]) - ); + atom.packages.activatePackage('language-coffee-script')); + + waitsForPromise(() => + atom.workspace.open(validPath)); + + atom.packages.triggerDeferredActivationHooks(); + waitsForPromise(() => activationPromise); }); it('finds nothing wrong with a valid file', () => { From 14edd72ab62beffa27375395769f396555f2f2e6 Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Fri, 18 Nov 2016 23:00:44 +0100 Subject: [PATCH 2/2] Remedy review feedback --- spec/linter-coffeelint-spec.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/spec/linter-coffeelint-spec.js b/spec/linter-coffeelint-spec.js index 7047439..6bceaf9 100644 --- a/spec/linter-coffeelint-spec.js +++ b/spec/linter-coffeelint-spec.js @@ -9,19 +9,14 @@ const lint = require('../lib/init.coffee').provideLinter().lint; describe('The CoffeeLint provider for Linter', () => { describe('works with CoffeeScript files and', () => { beforeEach(() => { - // This whole beforeEach function is inspired by: - // https://github.com/AtomLinter/linter-jscs/pull/295/files - // - // See also: - // https://discuss.atom.io/t/activationhooks-break-unit-tests/36028/8 + // Info about this beforeEach() implementation: + // https://github.com/AtomLinter/Meta/issues/15 const activationPromise = atom.packages.activatePackage('linter-coffeelint'); waitsForPromise(() => - atom.packages.activatePackage('language-coffee-script')); - - waitsForPromise(() => - atom.workspace.open(validPath)); + atom.packages.activatePackage('language-coffee-script').then(() => + atom.workspace.open(validPath))); atom.packages.triggerDeferredActivationHooks(); waitsForPromise(() => activationPromise);