Skip to content

Commit 1acf033

Browse files
committed
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: #44741 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent c9602ce commit 1acf033

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

test/fixtures/guess-hash-seed.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ function hash_to_bucket(hash, numBuckets) {
6767
function time_set_lookup(set, value) {
6868
const t1 = process.hrtime();
6969
for (let i = 0; i < 100; i++) {
70-
// annoyingly, SetHas() is JS code and therefore potentially optimizable.
71-
// However, SetHas() looks up the table using native code, and it seems like
72-
// that's sufficient to prevent the optimizer from doing anything?
7370
set.has(value);
7471
}
7572
const t = process.hrtime(t1);
@@ -78,6 +75,9 @@ function time_set_lookup(set, value) {
7875
return secs * 1e9 + nanos;
7976
}
8077

78+
// Prevent optimization of SetHas().
79+
%NeverOptimizeFunction(time_set_lookup);
80+
8181
// Set with 256 buckets; bucket 0 full, others empty
8282
const tester_set_buckets = 256;
8383
const tester_set = new Set();

test/pummel/test-hash-seed.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ const requiredCallback = common.mustCall((results) => {
2424
assert.strictEqual(seeds.length, kRepetitions);
2525
});
2626

27-
const generateSeed = () => execFilePromise(process.execPath, [targetScript]);
27+
function generateSeed() {
28+
return execFilePromise(process.execPath, [
29+
// Needed for %NeverOptimizeFunction.
30+
'--allow-natives-syntax',
31+
targetScript,
32+
]);
33+
}
34+
2835
const subprocesses = [...new Array(kRepetitions)].map(generateSeed);
2936

3037
Promise.all(subprocesses)

0 commit comments

Comments
 (0)