Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

object[key] assignment performance drop since 0.12 #25501

Closed
yamsellem opened this issue Jun 10, 2015 · 2 comments
Closed

object[key] assignment performance drop since 0.12 #25501

yamsellem opened this issue Jun 10, 2015 · 2 comments

Comments

@yamsellem
Copy link

We've found a performance drop in our production code when migrating to node 0.12.
Here is a benchmark that reproduces it:

var keys = ["5613","f9fa","45cb","b7c7","7556","f23b","e697","b75d","efd5","aafe","ca3d","7231","81c6"];

var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;

suite
.add('Object#keys', function() {
    var obj = {};
    for(var i in keys)
        obj[keys[i]] = {};
})
.add('Map#keys', function() {
    var map = new Map();
    for(var i in keys)
        map.set(keys[i], {});
})
.on('cycle', function(event) {
    console.log(String(event.target));
})
.run();

On node 0.10.24 (tested on 0.10.38 with similar results)

Object#keys x 216,605 ops/sec ±8.08% (86 runs sampled)

On node 0.12.4 (tested on 0.12.0 with similar results)

Object#keys x 89,854 ops/sec ±2.03% (85 runs sampled)
Map#keys x 331,112 ops/sec ±1.00% (98 runs sampled)

Does object structure has changed drastically in v8 new releases?
Is there something wrong with setting random string names as object keys?

// adding keys to the array worsen the results
keys = keys.concat("ee7a","3c4b","1abd","ad27");

// node 0.10.24 (10% slower)
Object#keys x 198,511 ops/sec ±0.52% (99 runs sampled)

// node 0.12.4 (30% slower)
Object#keys x 64,471 ops/sec ±2.15% (88 runs sampled)
Map#keys x 249,456 ops/sec ±0.98% (97 runs sampled)
@jasnell
Copy link
Member

jasnell commented Jun 24, 2015

Can you test the performance on this against io.js? I'm curious what the impact of the newer v8 would be.

@yamsellem
Copy link
Author

@jasnell Here is the last benchmarks including io.js (with keys.concat(4 other keys) as in my last post):

// node 0.10.24 (0.10.32 is similar)
Object#keys x 191,685 ops/sec ±1.91% (94 runs sampled)

// node 0.12.5 (0.12 is similar)
Object#keys x 67,488 ops/sec ±2.54% (84 runs sampled)
Map#keys x 243,826 ops/sec ±5.23% (87 runs sampled)

// io 1.8.2
Object#keys x 67,553 ops/sec ±4.12% (80 runs sampled)
Map#keys x 286,896 ops/sec ±2.16% (94 runs sampled)

// io 2.3.1 (2.0.0 is similar)
Object#keys x 25,633 ops/sec ±3.54% (77 runs sampled)
Map#keys x 293,148 ops/sec ±2.10% (94 runs sampled)

The performance of adding a key to an object seems hardly affected by v8 new releases.
But a ratio of 10 to 1 is hard to believe.

ps. you can test them on your computer as well, just copy the source file in my first post, npm install benchmark and run the source file with node

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants