Skip to content

Commit

Permalink
Merge pull request electron#3902 from bengotow/asar-perf
Browse files Browse the repository at this point in the history
Add env var to export a hint file to optimize ASAR ordering
  • Loading branch information
zcbenz committed Jan 21, 2016
2 parents b614c48 + ed34e33 commit b039741
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 21 additions & 1 deletion atom/common/lib/asar.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,24 @@

// Override fs APIs.
exports.wrapFsWithAsar = function(fs) {
var exists, existsSync, internalModuleReadFile, internalModuleStat, lstat, lstatSync, mkdir, mkdirSync, readFile, readFileSync, readdir, readdirSync, realpath, realpathSync, stat, statSync, statSyncNoException;
var exists, existsSync, internalModuleReadFile, internalModuleStat, lstat, lstatSync, mkdir, mkdirSync, readFile, readFileSync, readdir, readdirSync, realpath, realpathSync, stat, statSync, statSyncNoException, logFDs, logASARAccess;

logFDs = {};
logASARAccess = function(asarPath, filePath, offset) {
if (!process.env.ELECTRON_LOG_ASAR_READS) {
return;
}
if (!logFDs[asarPath]) {
var logFilename, logPath;
const path = require('path');
logFilename = path.basename(asarPath, '.asar') + '-access-log.txt';
logPath = path.join(require('os').tmpdir(), logFilename);
logFDs[asarPath] = fs.openSync(logPath, 'a');
console.log('Logging ' + asarPath + ' access to ' + logPath);
}
fs.writeSync(logFDs[asarPath], offset + ': ' + filePath + '\n');
};

lstatSync = fs.lstatSync;
fs.lstatSync = function(p) {
var archive, asarPath, filePath, isAsar, ref, stats;
Expand Down Expand Up @@ -395,6 +412,7 @@
if (!(fd >= 0)) {
return notFoundError(asarPath, filePath, callback);
}
logASARAccess(asarPath, filePath, info.offset);
return fs.read(fd, buffer, 0, info.size, info.offset, function(error) {
return callback(error, encoding ? buffer.toString(encoding) : buffer);
});
Expand Down Expand Up @@ -444,6 +462,7 @@
if (!(fd >= 0)) {
notFoundError(asarPath, filePath);
}
logASARAccess(asarPath, filePath, info.offset);
fs.readSync(fd, buffer, 0, info.size, info.offset);
if (encoding) {
return buffer.toString(encoding);
Expand Down Expand Up @@ -516,6 +535,7 @@
if (!(fd >= 0)) {
return void 0;
}
logASARAccess(asarPath, filePath, info.offset);
fs.readSync(fd, buffer, 0, info.size, info.offset);
return buffer.toString('utf8');
};
Expand Down
6 changes: 6 additions & 0 deletions docs/api/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ Starts the process as a normal Node.js process.

Prints Chrome's internal logging to console.

## `ELECTRON_LOG_ASAR_READS`

When Electron reads from an ASAR file, log the read offset and file path to
the system `tmpdir`. The resulting file can be provided to the ASAR module
to optimize file ordering.

## `ELECTRON_ENABLE_STACK_DUMPING`

When Electron crashed, prints the stack trace to console.
Expand Down

0 comments on commit b039741

Please sign in to comment.