mirror of https://github.com/nodejs/node.git
test: fix test-hash-seed for new V8 versions
The test relied on V8 not optimizing functions that use `set.has()`. Force V8 to not optimize it now that TurboFan knows about this method. PR-URL: https://github.com/nodejs/node/pull/44741 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>pull/44962/head
parent
c9602ce212
commit
1acf0339dd
|
@ -67,9 +67,6 @@ function hash_to_bucket(hash, numBuckets) {
|
|||
function time_set_lookup(set, value) {
|
||||
const t1 = process.hrtime();
|
||||
for (let i = 0; i < 100; i++) {
|
||||
// annoyingly, SetHas() is JS code and therefore potentially optimizable.
|
||||
// However, SetHas() looks up the table using native code, and it seems like
|
||||
// that's sufficient to prevent the optimizer from doing anything?
|
||||
set.has(value);
|
||||
}
|
||||
const t = process.hrtime(t1);
|
||||
|
@ -78,6 +75,9 @@ function time_set_lookup(set, value) {
|
|||
return secs * 1e9 + nanos;
|
||||
}
|
||||
|
||||
// Prevent optimization of SetHas().
|
||||
%NeverOptimizeFunction(time_set_lookup);
|
||||
|
||||
// Set with 256 buckets; bucket 0 full, others empty
|
||||
const tester_set_buckets = 256;
|
||||
const tester_set = new Set();
|
||||
|
|
|
@ -24,7 +24,14 @@ const requiredCallback = common.mustCall((results) => {
|
|||
assert.strictEqual(seeds.length, kRepetitions);
|
||||
});
|
||||
|
||||
const generateSeed = () => execFilePromise(process.execPath, [targetScript]);
|
||||
function generateSeed() {
|
||||
return execFilePromise(process.execPath, [
|
||||
// Needed for %NeverOptimizeFunction.
|
||||
'--allow-natives-syntax',
|
||||
targetScript,
|
||||
]);
|
||||
}
|
||||
|
||||
const subprocesses = [...new Array(kRepetitions)].map(generateSeed);
|
||||
|
||||
Promise.all(subprocesses)
|
||||
|
|
Loading…
Reference in New Issue