Skip to content

NodeJs Smi-Array vs Pure V8 Smi-Array Performance #48524

@demimurych

Description

@demimurych

Version

v20.3.0

Platform

Linux murych-hive 5.4.0-148-lowlatency #165-Ubuntu SMP PREEMPT Tue Apr 18 09:36:22 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

noop

What steps will reproduce the bug?

file.js

"use strict";
var arr = [];
var size = 10000000;
var test_times = 50;

for ( var i = 0; i < size; i++ ) {
	arr.push( i )
}

for ( var i = 0; i < test_times; i++ ) {
	var test = arr.indexOf( 9999999 )
}

/usr/bin/time -f "Time: %e" /usr/bin/node ./file.js

Time: 1.32

this code will be much slower than in pure v8.
/usr/bin/time -f "Time: %e" /usr/bin/d8 ./file.js

Time: 0.36

How often does it reproduce? Is there a required condition?

no

What is the expected behavior? Why is that the expected behavior?

There should be no discrepancy between v8 and node with such a large gap.

What do you see instead?

The first example slower than the second

Additional information

that's not all.
file2.js

"use strict";
var arr = [];
var size = 10000000;
var test_times = 50;



for ( var i = 0; i < size; i++ ) {
	arr.push( i + 0.1 )
}

for ( var i = 0; i < test_times; i++ ) {
	var test = arr.indexOf( 9999999.1 )
}

Runs faster than the first example.
/usr/bin/time -f "Time: %e" /usr/bin/node ./file.js

Time: 1.32

/usr/bin/time -f "Time: %e" /usr/bin/node ./file2.js

Time: 0.90

The first example operates on SMI in array
The second example operates on Double in array

How in Node double which is located in heap is faster than smi which located directly in array ?

In pure v8 everything works as expected.
/usr/bin/time -f "Time: %e" /usr/bin/d8 ./file.js

Time: 0.36

/usr/bin/time -f "Time: %e" /usr/bin/d8 ./file2.js

Time: 0.59

That is, double is slower than smi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions