Skip to content

Maps are slow in hashlink #607

@apxapob

Description

@apxapob

Here is my test code:

function mapTest() {
    var start = Timer.stamp();
    var N = 1000000;

    var map:Map<String, Int> = [];
    for (i in 0...N){//set
      map.set(i+'', i);
    }
    trace("1 step time:", Timer.stamp() - start);
    for (key in map.keys()){//get
      var a = map.get(key);
      a++;
    }
    trace("2 step time:", Timer.stamp() - start);
    for (i in 0...N){//remove
      map.remove(i+'');
    }
    trace("total time:", Timer.stamp() - start);
  }

And here are my results for N = 1 000 000:
1 step time: 0.400216579437256
2 step time: 0.55933403968811
total time: 20.15642786026

Hashlink:
1000 => total time: 0.000833272933959961
10000 => total time: 0.0115585327148438
100000 => total time: 0.325639247894287
1000000 => total time: 20.6692686080933
10000000 => total time: ???

the same code compiled for Javascript:
1000 => total time: 0.0005000000000000004
10000 => total time: 0.001600000001490104
100000 => total time: 0.015400000002235181
1000000 => total time: 0.16799999999999998
10000000 => total time: 2.606199999999255

Also I tried IntMaps they're faster at setting and getting but slower at removing.

Anyway set and get are also slow. Javascript completes the whole test 2 times faster than Hashlink only step 1.

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