Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport v7.x - #9615 - benchmark: remove %OptimizeFunctionOnNextCall #11744

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,3 @@ it returns to accomplish what they need. This function reports timing
data to the parent process (usually created by running `compare.js`, `run.js` or
`scatter.js`).

### v8ForceOptimization(method[, ...args])

Force V8 to mark the `method` for optimization with the native function
`%OptimizeFunctionOnNextCall()` and return the optimization status
after that.

It can be used to prevent the benchmark from getting disrupted by the optimizer
kicking in halfway through. However, this could result in a less effective
optimization. In general, only use it if you know what it actually does.
4 changes: 0 additions & 4 deletions benchmark/buffers/buffer-compare-instance-method.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
const common = require('../common.js');
const v8 = require('v8');

const bench = common.createBenchmark(main, {
size: [16, 512, 1024, 4096, 16386],
Expand All @@ -20,7 +19,6 @@ function main(conf) {

b1[size - 1] = 'b'.charCodeAt(0);

// Force optimization before starting the benchmark
switch (args) {
case 2:
b0.compare(b1, 0);
Expand All @@ -37,8 +35,6 @@ function main(conf) {
default:
b0.compare(b1);
}
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(b0.compare)');
switch (args) {
case 2:
b0.compare(b1, 0);
Expand Down
23 changes: 0 additions & 23 deletions benchmark/buffers/buffer-compare-offset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
const common = require('../common.js');
const v8 = require('v8');

const bench = common.createBenchmark(main, {
method: ['offset', 'slice'],
Expand All @@ -9,18 +8,6 @@ const bench = common.createBenchmark(main, {
});

function compareUsingSlice(b0, b1, len, iter) {

// Force optimization before starting the benchmark
Buffer.compare(b0.slice(1, len), b1.slice(1, len));
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(Buffer.compare)');
eval('%OptimizeFunctionOnNextCall(b0.slice)');
eval('%OptimizeFunctionOnNextCall(b1.slice)');
Buffer.compare(b0.slice(1, len), b1.slice(1, len));
doCompareUsingSlice(b0, b1, len, iter);
}

function doCompareUsingSlice(b0, b1, len, iter) {
var i;
bench.start();
for (i = 0; i < iter; i++)
Expand All @@ -29,16 +16,6 @@ function doCompareUsingSlice(b0, b1, len, iter) {
}

function compareUsingOffset(b0, b1, len, iter) {
len = len + 1;
// Force optimization before starting the benchmark
b0.compare(b1, 1, len, 1, len);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(b0.compare)');
b0.compare(b1, 1, len, 1, len);
doCompareUsingOffset(b0, b1, len, iter);
}

function doCompareUsingOffset(b0, b1, len, iter) {
var i;
bench.start();
for (i = 0; i < iter; i++)
Expand Down
5 changes: 1 addition & 4 deletions benchmark/buffers/buffer-swap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const common = require('../common.js');
const v8 = require('v8');

const bench = common.createBenchmark(main, {
aligned: ['true', 'false'],
Expand Down Expand Up @@ -81,9 +80,7 @@ function main(conf) {
const buf = createBuffer(len, aligned === 'true');
const bufferSwap = genMethod(method);

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

bufferSwap(n, buf);
bench.start();
bufferSwap(n, buf);
bench.end(n);
Expand Down
14 changes: 0 additions & 14 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,3 @@ Benchmark.prototype.report = function(rate, elapsed) {
type: 'report'
});
};

exports.v8ForceOptimization = function(method) {
if (typeof method !== 'function')
return;

const v8 = require('v8');
v8.setFlagsFromString('--allow_natives_syntax');

const args = Array.prototype.slice.call(arguments, 1);
method.apply(null, args);
eval('%OptimizeFunctionOnNextCall(method)');
method.apply(null, args);
return eval('%GetOptimizationStatus(method)');
};
9 changes: 6 additions & 3 deletions benchmark/crypto/get-ciphers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ function main(conf) {
const v = conf.v;
const method = require(v).getCiphers;
var i = 0;

common.v8ForceOptimization(method);
// first call to getChipers will dominate the results
if (n > 1) {
for (; i < n; i++)
method();
}
bench.start();
for (; i < n; i++) method();
for (i = 0; i < n; i++) method();
bench.end(n);
}
4 changes: 0 additions & 4 deletions benchmark/es/defaultparams-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ function defaultParams(x = 1, y = 2) {

function runOldStyleDefaults(n) {

common.v8ForceOptimization(oldStyleDefaults);

var i = 0;
bench.start();
for (; i < n; i++)
Expand All @@ -33,8 +31,6 @@ function runOldStyleDefaults(n) {

function runDefaultParams(n) {

common.v8ForceOptimization(defaultParams);

var i = 0;
bench.start();
for (; i < n; i++)
Expand Down
6 changes: 0 additions & 6 deletions benchmark/es/restparams-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ function useArguments() {

function runCopyArguments(n) {

common.v8ForceOptimization(copyArguments, 1, 2, 'a', 'b');

var i = 0;
bench.start();
for (; i < n; i++)
Expand All @@ -46,8 +44,6 @@ function runCopyArguments(n) {

function runRestArguments(n) {

common.v8ForceOptimization(restArguments, 1, 2, 'a', 'b');

var i = 0;
bench.start();
for (; i < n; i++)
Expand All @@ -57,8 +53,6 @@ function runRestArguments(n) {

function runUseArguments(n) {

common.v8ForceOptimization(useArguments, 1, 2, 'a', 'b');

var i = 0;
bench.start();
for (; i < n; i++)
Expand Down
13 changes: 0 additions & 13 deletions benchmark/misc/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ const common = require('../common.js');
const assert = require('assert');
const Writable = require('stream').Writable;
const util = require('util');
const v8 = require('v8');

v8.setFlagsFromString('--allow_natives_syntax');

const methods = [
'restAndSpread',
Expand Down Expand Up @@ -51,14 +48,7 @@ function usingArgumentsAndApplyC() {
nullStream.write(util.format.apply(null, arguments) + '\n');
}

function optimize(method, ...args) {
method(...args);
eval(`%OptimizeFunctionOnNextCall(${method.name})`);
method(...args);
}

function runUsingRestAndConcat(n) {
optimize(usingRestAndConcat, 'a', 1);

var i = 0;
bench.start();
Expand All @@ -70,7 +60,6 @@ function runUsingRestAndConcat(n) {
function runUsingRestAndSpread(n, concat) {

const method = concat ? usingRestAndSpreadC : usingRestAndSpreadTS;
optimize(method, 'this is %s of %d', 'a', 1);

var i = 0;
bench.start();
Expand All @@ -82,7 +71,6 @@ function runUsingRestAndSpread(n, concat) {
function runUsingRestAndApply(n, concat) {

const method = concat ? usingRestAndApplyC : usingRestAndApplyTS;
optimize(method, 'this is %s of %d', 'a', 1);

var i = 0;
bench.start();
Expand All @@ -94,7 +82,6 @@ function runUsingRestAndApply(n, concat) {
function runUsingArgumentsAndApply(n, concat) {

const method = concat ? usingArgumentsAndApplyC : usingArgumentsAndApplyTS;
optimize(method, 'this is %s of %d', 'a', 1);

var i = 0;
bench.start();
Expand Down
6 changes: 3 additions & 3 deletions benchmark/misc/punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ function usingICU(val) {
}

function runPunycode(n, val) {
common.v8ForceOptimization(usingPunycode, val);
var i = 0;
bench.start();
for (; i < n; i++)
usingPunycode(val);
bench.start();
for (i = 0; i < n; i++)
usingPunycode(val);
bench.end(n);
}

function runICU(n, val) {
common.v8ForceOptimization(usingICU, val);
var i = 0;
bench.start();
for (; i < n; i++)
Expand Down
8 changes: 0 additions & 8 deletions benchmark/misc/util-extend-vs-object-assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const common = require('../common.js');
const util = require('util');
const v8 = require('v8');

const bench = common.createBenchmark(main, {
type: ['extend', 'assign'],
Expand All @@ -12,25 +11,18 @@ const bench = common.createBenchmark(main, {
function main(conf) {
let fn;
const n = conf.n | 0;
let v8command;

if (conf.type === 'extend') {
fn = util._extend;
v8command = '%OptimizeFunctionOnNextCall(util._extend)';
} else if (conf.type === 'assign') {
fn = Object.assign;
// Object.assign is built-in, cannot be optimized
v8command = '';
}

// Force-optimize the method to test so that the benchmark doesn't
// get disrupted by the optimizer kicking in halfway through.
for (var i = 0; i < conf.type.length * 10; i += 1)
fn({}, process.env);

v8.setFlagsFromString('--allow_natives_syntax');
eval(v8command);

var obj = new Proxy({}, { set: function(a, b, c) { return true; } });

bench.start();
Expand Down
7 changes: 0 additions & 7 deletions benchmark/path/basename-posix.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
pathext: [
Expand Down Expand Up @@ -30,12 +29,6 @@ function main(conf) {
input = input.slice(0, extIdx);
}

// Force optimization before starting the benchmark
p.basename(input, ext);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.basename)');
p.basename(input, ext);

bench.start();
for (var i = 0; i < n; i++) {
p.basename(input, ext);
Expand Down
7 changes: 0 additions & 7 deletions benchmark/path/basename-win32.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
pathext: [
Expand Down Expand Up @@ -30,12 +29,6 @@ function main(conf) {
input = input.slice(0, extIdx);
}

// Force optimization before starting the benchmark
p.basename(input, ext);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.basename)');
p.basename(input, ext);

bench.start();
for (var i = 0; i < n; i++) {
p.basename(input, ext);
Expand Down
7 changes: 0 additions & 7 deletions benchmark/path/dirname-posix.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
path: [
Expand All @@ -21,12 +20,6 @@ function main(conf) {
var p = path.posix;
var input = '' + conf.path;

// Force optimization before starting the benchmark
p.dirname(input);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.dirname)');
p.dirname(input);

bench.start();
for (var i = 0; i < n; i++) {
p.dirname(input);
Expand Down
7 changes: 0 additions & 7 deletions benchmark/path/dirname-win32.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
path: [
Expand All @@ -21,12 +20,6 @@ function main(conf) {
var p = path.win32;
var input = '' + conf.path;

// Force optimization before starting the benchmark
p.dirname(input);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.dirname)');
p.dirname(input);

bench.start();
for (var i = 0; i < n; i++) {
p.dirname(input);
Expand Down
7 changes: 0 additions & 7 deletions benchmark/path/extname-posix.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
path: [
Expand All @@ -24,12 +23,6 @@ function main(conf) {
var p = path.posix;
var input = '' + conf.path;

// Force optimization before starting the benchmark
p.extname(input);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.extname)');
p.extname(input);

bench.start();
for (var i = 0; i < n; i++) {
p.extname(input);
Expand Down
Loading