How to use v8 - 10 common examples

To help you get started, we’ve selected a few v8 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github peterbraden / node-opencv / test / memory.js View on Github external
require("v8").setFlagsFromString('--expose_gc');
var gc = require("vm").runInNewContext('gc');

var fs = require('fs')
  , path = require('path') 
  , test = require('tape')
  , cv = require('../lib/opencv');

 var IMAGE_PATH = path.resolve(__dirname, '../examples/files', 'mona.png');
 var VIDEO_PATH = path.resolve(__dirname, '../examples/files', 'motion.mov');
 var TEMP_SAVE_PATH = path.resolve(__dirname, '../examples/tmp', 'out.jpg');
 var TEMP_VIDEO_PATH = path.resolve(__dirname, '../examples/tmp', 'out.mp4');

// These tests check that every function that creates or modifies a Matrix handles its externally tracked memory correctly.
// Since the memory tracker uses OpenCV's reference counting to determine when to tell Node about memory changes,
// it is important that only Matrix objects that Javascript knows about retain references to internal OpenCV Mat objects.
// Reference counts for newly created objects should ususally therefore be 1, and releasing them should alter the 
github techtacoriginal / offlinebay / app / main-functions / import-dump.js View on Github external
/* Tested to be working with the TPB dump at best. Extremely fast, zero Memory leaks and no garbage collection needed.
*  Process exits immediately. Put together to work with papaparse */

const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
require('v8').setFlagsFromString('--harmony'); //To fix the regex Lookbehind issue

// Keep the application from crashing on unexpected errors
process.on('uncaughtException', function (error) {
    console.log(error);
    process.send(['import-failed', 'general']); //mainWindow.webContents.send('import-failed', 'general');
});

let args = process.argv.slice(2);
let isUpd = (args[0] === 'true');
let filePath = args[1];
let timestamp = args[2];
let keepDL = (args[3] === 'true');
let stagePath = path.join(process.cwd(), 'data', 'stage.csv');
let extract = path.join(process.cwd(), 'data', 'downloads', 'torrent_dump_full.csv');
let totalLines = 0;
github t9md / atom-narrow / lib / utils.js View on Github external
function startMeasureMemory (subject, simple = true) {
  if (ignoreSubject.includes(subject)) {
    return () => {}
  }
  console.time(subject)

  const v8 = require('v8')
  const before = v8.getHeapStatistics()
  console.time(subject)
  return function () {
    const after = v8.getHeapStatistics()
    const diff = {}
    for (let key of Object.keys(before)) {
      diff[key] = after[key] - before[key]
    }

    console.info(`= ${subject}`)
    if (simple) {
      console.timeEnd(subject)
      // console.log("diff.used_heap_size", toMB(diff.used_heap_size))
    } else {
      const table = [before, after, diff]
      for (let result of table) {
        for (const key in result) {
github facebook / jest / packages / jest-leak-detector / src / index.ts View on Github external
private _runGarbageCollector() {
    const isGarbageCollectorHidden = !global.gc;

    // GC is usually hidden, so we have to expose it before running.
    setFlagsFromString('--expose-gc');
    runInNewContext('gc')();

    // The GC was not initially exposed, so let's hide it again.
    if (isGarbageCollectorHidden) {
      setFlagsFromString('--no-expose-gc');
    }
  }
}
github seven1986 / oauthapp / IdentityServer4.MicroService.Host / node_modules / natives / index.js View on Github external
};
    }
    return req_(id, cache)
  }

  var nm = {
    exports: {},
    loading: true,
    loaded: false,
    filename: id + '.js'
  }
  cache[id] = nm
  var fn
  var setV8Flags = false
  try {
    require('v8').setFlagsFromString('--allow_natives_syntax')
    setV8Flags = true
  } catch (e) {}
  try {
    /* istanbul ignore else */
    if (ContextifyScript) {
      fn = runInThisContext(source, {
        filename: nm.filename,
        lineOffset: 0,
        displayErrors: true
      });
    } else {
      fn = runInThisContext(source, nm.filename, true);
    }
    fn(nm.exports, cachingRequire, nm, nm.filename)
    nm.loaded = true
  } finally {
github pmq20 / node-packer / vendor / node / benchmark / url / new-url-parse.js View on Github external
function useOld(n, input) {
  // Force-optimize url.parse() so that the benchmark doesn't get
  // disrupted by the optimizer kicking in halfway through.
  url.parse(input);
  v8.setFlagsFromString('--allow_natives_syntax');
  eval('%OptimizeFunctionOnNextCall(url.parse)');

  bench.start();
  for (var i = 0; i < n; i += 1)
    url.parse(input);
  bench.end(n);
}
github pmq20 / node-packer / vendor / node / benchmark / url / url-resolve.js View on Github external
function main(conf) {
  var n = conf.n | 0;
  var href = hrefs[conf.href];
  var path = paths[conf.path];

  // Force-optimize url.resolve() so that the benchmark doesn't get
  // disrupted by the optimizer kicking in halfway through.
  url.resolve(href, path);
  v8.setFlagsFromString('--allow_natives_syntax');
  eval('%OptimizeFunctionOnNextCall(url.resolve)');

  bench.start();
  for (var i = 0; i < n; i += 1)
    url.resolve(href, path);
  bench.end(n);
}
github pmq20 / node-packer / node / benchmark / url / url-parse.js View on Github external
var inputs = {
    one: 'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj',
    two: 'http://blog.nodejs.org/',
    three: 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en',
    four: 'javascript:alert("node is awesome");',
    five: 'some.ran/dom/url.thing?oh=yes#whoo',
    six: 'https://user:pass@example.com/',
  };
  var input = inputs[type] || '';

  // Force-optimize url.parse() so that the benchmark doesn't get
  // disrupted by the optimizer kicking in halfway through.
  for (var name in inputs)
    url.parse(inputs[name]);

  v8.setFlagsFromString('--allow_natives_syntax');
  eval('%OptimizeFunctionOnNextCall(url.parse)');

  bench.start();
  for (var i = 0; i < n; i += 1)
    url.parse(input);
  bench.end(n);
}
github keymetrics / pm2-io-apm / src / metrics / v8.ts View on Github external
this.timer = setInterval(() => {
      const stats = v8.getHeapStatistics()
      // update each metrics that we declared
      for (let metricName in this.metricsDefinitions) {
        if (typeof stats[metricName] !== 'number') continue
        const gauge = this.metricStore.get(metricName)
        if (gauge === undefined) continue
        gauge.set(this.formatMiBytes(stats[metricName]))
      }
      // manually compute the heap usage
      const usage = (stats.used_heap_size / stats.total_heap_size * 100).toFixed(2)
      const usageMetric = this.metricStore.get('heap_used_percent')
      if (usageMetric !== undefined) {
        usageMetric.set(parseFloat(usage))
      }
    }, this.TIME_INTERVAL)
github mendersoftware / gui / node_modules / natives / index.js View on Github external
};
    }
    return req_(id, cache)
  }

  var nm = {
    exports: {},
    loading: true,
    loaded: false,
    filename: id + '.js'
  }
  cache[id] = nm
  var fn
  var setV8Flags = false
  try {
    require('v8').setFlagsFromString('--allow_natives_syntax')
    setV8Flags = true
  } catch (e) {}
  try {
    /* istanbul ignore else */
    if (ContextifyScript) {
      fn = runInThisContext(source, {
        filename: nm.filename,
        lineOffset: 0,
        displayErrors: true
      });
    } else {
      fn = runInThisContext(source, nm.filename, true);
    }
    fn(nm.exports, cachingRequire, nm, nm.filename)
    nm.loaded = true
  } finally {

v8

v8

MIT
Latest version published 9 years ago

Package Health Score

45 / 100
Full package analysis