Immutable-js: What causes Map to choose BitmapIndexedNode over ArrayMapNode?

Created on 3 Mar 2016  路  3Comments  路  Source: immutable-js/immutable-js

I am working with a pretty easy structure

[{
    "id": 1,
    "name": "Example",
    "parent_id": null,
    "order": 0,
    "is_open": false,
    "is_directory": true,
    "meta": {
        "revision": 0,
        "created": 1456997356672,
        "version": 0
    },
    "$loki": 1,
    "children": []
}, {
    "id": 5,
    "name": "Double dip",
    "parent_id": null,
    "order": 0,
    "is_open": false,
    "is_directory": true,
    "meta": {
        "revision": 0,
        "created": 1456997356672,
        "version": 0
    },
    "$loki": 5,
    "children": []
}]

However what I get back from Immutable.fromJS(...) is a List with two BitmapIndexedNode

Most helpful comment

It is 8 entries. This is a performance optimization where the each of these implementations have different performance characteristics for getting and setting, and ~8 entries is where BitmapIndexedNode begins to outperform ArrayMapNode.

All 3 comments

I haven't found the direct cause, but the structure appears not to matter. It's when you have more than 8 items.

{
  one: 1,
  two: 2,
  three: 3,
  four: 4,
  five: 5,
  six: 6,
  seven: 7,
  eight: 8
}
=> ArrayMapNode
{
  one: 1,
  two: 2,
  three: 3,
  four: 4,
  five: 5,
  six: 6,
  seven: 7,
  eight: 8,
  nine: 9
}
=> BitmapIndexedNode

It is 8 entries. This is a performance optimization where the each of these implementations have different performance characteristics for getting and setting, and ~8 entries is where BitmapIndexedNode begins to outperform ArrayMapNode.

Thanks @leebyron

Was this page helpful?
0 / 5 - 0 ratings

Related issues

s-panferov picture s-panferov  路  4Comments

sterpe picture sterpe  路  4Comments

coodoo picture coodoo  路  3Comments

Daniel15 picture Daniel15  路  4Comments

evenstensberg picture evenstensberg  路  4Comments