Ver Fonte

startup time speedup

Eugene Pankov há 7 anos atrás
pai
commit
46d8533fee
4 ficheiros alterados com 18 adições e 0 exclusões
  1. 15 0
      app/lru.js
  2. 1 0
      app/main.js
  3. 1 0
      app/src/entry.preload.ts
  4. 1 0
      app/webpack.config.js

+ 15 - 0
app/lru.js

@@ -0,0 +1,15 @@
+var lru = require('lru-cache')({max: 256, maxAge: 250/*ms*/});
+
+var fs = require('fs');
+var origLstat = fs.realpathSync.bind(fs);
+console.log('s')
+// NB: The biggest offender of thrashing realpathSync is the node module system
+// itself, which we can't get into via any sane means.
+require('fs').realpathSync = function(p) {
+  let r = lru.get(p);
+  if (r) return r;
+
+  r = origLstat(p);
+  lru.set(p, r);
+  return r;
+};

+ 1 - 0
app/main.js

@@ -1,3 +1,4 @@
+require('./lru.js')
 if (process.platform == 'win32' && require('electron-squirrel-startup')) process.exit(0)
 
 const electron = require('electron')

+ 1 - 0
app/src/entry.preload.ts

@@ -1,3 +1,4 @@
+import '../lru.js'
 import 'source-sans-pro'
 import 'font-awesome/css/font-awesome.css'
 import 'ngx-toastr/toastr.css'

+ 1 - 0
app/webpack.config.js

@@ -64,6 +64,7 @@ module.exports = {
     'child_process': 'commonjs child_process',
     'electron': 'commonjs electron',
     'electron-is-dev': 'commonjs electron-is-dev',
+    'fs': 'commonjs fs',
     'ngx-toastr': 'commonjs ngx-toastr',
     'module': 'commonjs module',
     'mz': 'commonjs mz',