Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Conversation

@BinaryMuse
Copy link
Contributor

@BinaryMuse BinaryMuse commented Apr 4, 2017

There are a bunch of changes necessary to support snapshotting in Atom. The snapshot will walk the require graph and pull in all the files to the snapshot, and then execute them in a raw V8 context. This means we get no require.resolve, no console.*, no atom, etc. So we need to move usage of those types of things until they're actually needed.

  • Drop the semver check inside the main entry point
  • Get things like Emitter and Disposable from event-kit instead of atom
  • Defer the use of require.resolve until it's actually needed
  • Defer the creation of the GithubPackage instance until the package is activated (because we have no atom to use to pass items into the constructor)
  • Use getPackageRoot() strategy to launch bins
  • Fix or defer loading of packages that use unavailable APIs at require time

In conjunction with atom/atom#14131

Fixes #618

@BinaryMuse BinaryMuse force-pushed the mkt-ku-simplify-package-startup branch from 331a1c2 to d14450f Compare April 4, 2017 19:53
return instance;
}

constructor(Strategy = strategies.find(strat => strat.isValid())) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this check to the first time we actually try to use the strategy saves around ~100ms on the package's initial render (called from activate).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option might be to default to the real Keytar strategy and toggle to the shelling-out one with an environment variable or a (hidden?) config setting. Annoying for those of us who run master, but it'd keep us from paying any performance penalty for the common case of being bundled in a proper Atom distro.

@BinaryMuse BinaryMuse force-pushed the mkt-ku-simplify-package-startup branch from cc625f9 to 9ad8629 Compare April 6, 2017 07:56
This ensures that the instance is available before any consume* or
deserialize* hooks are called
@BinaryMuse
Copy link
Contributor Author

This now requires only the following additions to the snapshot creation script in atom/atom when we're ready to bundle:

diff --git a/script/lib/generate-startup-snapshot.js b/script/lib/generate-startup-snapshot.js
index 26761fc69..9eaa5f59c 100644
--- a/script/lib/generate-startup-snapshot.js
+++ b/script/lib/generate-startup-snapshot.js
@@ -27,6 +27,7 @@ module.exports = function (packagedAppPath) {
         modulePath.endsWith('.node') ||
         coreModules.has(modulePath) ||
         (relativePath.startsWith(path.join('..', 'src')) && relativePath.endsWith('-element.js')) ||
+        relativePath.startsWith(path.join('..', 'node_modules', 'dugite')) ||
         relativePath == path.join('..', 'exports', 'atom.js') ||
         relativePath == path.join('..', 'src', 'electron-shims.js') ||
         relativePath == path.join('..', 'src', 'safe-clipboard.js') ||
@@ -37,6 +38,7 @@ module.exports = function (packagedAppPath) {
         relativePath == path.join('..', 'node_modules', 'cson-parser', 'node_modules', 'coffee-script', 'lib', 'coffee-script', 'register.js') ||
         relativePath == path.join('..', 'node_modules', 'decompress-zip', 'lib', 'decompress-zip.js') ||
         relativePath == path.join('..', 'node_modules', 'debug', 'node.js') ||
+        relativePath == path.join('..', 'node_modules', 'fs-extra', 'lib', 'index.js') ||
         relativePath == path.join('..', 'node_modules', 'git-utils', 'lib', 'git.js') ||
         relativePath == path.join('..', 'node_modules', 'glob', 'glob.js') ||
         relativePath == path.join('..', 'node_modules', 'graceful-fs', 'graceful-fs.js') ||
@@ -47,6 +49,8 @@ module.exports = function (packagedAppPath) {
         relativePath == path.join('..', 'node_modules', 'less', 'lib', 'less-node', 'index.js') ||
         relativePath == path.join('..', 'node_modules', 'less', 'node_modules', 'graceful-fs', 'graceful-fs.js') ||
         relativePath == path.join('..', 'node_modules', 'minimatch', 'minimatch.js') ||
+        relativePath == path.join('..', 'node_modules', 'node-fetch', 'lib', 'fetch-error.js') ||
+        relativePath == path.join('..', 'node_modules', 'nsfw', 'node_modules', 'fs-extra', 'lib', 'index.js') ||
         relativePath == path.join('..', 'node_modules', 'superstring', 'index.js') ||
         relativePath == path.join('..', 'node_modules', 'oniguruma', 'lib', 'oniguruma.js') ||
         relativePath == path.join('..', 'node_modules', 'request', 'index.js') ||

Copy link
Contributor

@smashwilson smashwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

import React from 'react';

import {Point, Emitter} from 'atom';
import {Point} from 'atom';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, this import still works? I thought you'd meant that none of the Atom imports would work properly when bundled. Does it just have to do with the timing of when Emitter and CompositeDisposable are installed in the Atom global?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Point after activation, so it works fine. We had to bring in event-kit for Emitter and friends in other places, so it made sense to replace it package-wide.

import {CompositeDisposable} from 'event-kit';

import {GitProcess} from 'git-kitchen-sink';
import {GitProcess} from 'dugite';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for getting this upgrade in here 😄

}

return DUGITE_PATH;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 cool, cool

}

export function deleteFileOrFolder(path) {
export function deleteFileOrFolder(fileOrFolder) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 I always do this. "path" is such a natural name to use as a variable...

return instance;
}

constructor(Strategy = strategies.find(strat => strat.isValid())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option might be to default to the real Keytar strategy and toggle to the shelling-out one with an environment variable or a (hidden?) config setting. Annoying for those of us who run master, but it'd keep us from paying any performance penalty for the common case of being bundled in a proper Atom distro.

}
} else {
return this.props.maximumCharacterLimit;
return this.props.maximumCharacterLimit || '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@BinaryMuse BinaryMuse merged commit 06c35e9 into master Apr 11, 2017
@BinaryMuse BinaryMuse deleted the mkt-ku-simplify-package-startup branch April 11, 2017 04:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prepare package for bundling

3 participants