I've noticed that String.prototype.split's performance has degraded between node versions. Any idea what could be causing this?
| node | ops/sec |
| ------------- |:-------------:|
| 4 | 11,302,467 |
| 6 | 10,896,220 |
| 8 | 8,753,949 |
| 9 | 9,217,843 |
@ruimarinho Could you provide the benchmark code?
cc @nodejs/performance, @nodejs/v8.
Install benchmark:
npm i benchmark
Code:
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
suite.add('String#split', function() {
'FOO-BAR'.split('-');
}).on('cycle', function(event) {
console.log(String(event.target));
}).run({ async: true });
@ruimarinho I think this is caused by Crankshaft-to-Turbofan transition period. With V8 6.3 and 6.4, the performance is even better than in Node v4 and v6. My results in Windows 7 x64:
Node.js 4 (V8 4.5) String#split x 5,299,950 ops/sec 卤0.88% (91 runs sampled)
Node.js 6 (v8 5.1) String#split x 5,747,220 ops/sec 卤1.77% (97 runs sampled)
Node.js 8 (v8 6.1) String#split x 4,721,536 ops/sec 卤0.56% (99 runs sampled)
Node.js 9 (V8 6.2) String#split x 4,932,482 ops/sec 卤0.44% (102 runs sampled)
Node.js 9 (V8 6.3) String#split x 8,058,390 ops/sec 卤0.47% (107 runs sampled) // canary build
Node.js 10 (V8 6.4) String#split x 8,067,840 ops/sec 卤0.52% (104 runs sampled) // canary build
You can check with these canary builds:
cc @schuay
Opened https://crbug.com/v8/7103 for possible improvements to String.p.split. There shouldn't be a huge difference between somewhat recent V8 versions, Both the old JS- and new CSA implementation call into Runtime::kStringSplit which is expected to be quite slow in this simple case of short string subject and pattern.
There doesn't seem to be much actionable here on Node's part. I'll close this out for now.
Most helpful comment
There doesn't seem to be much actionable here on Node's part. I'll close this out for now.