Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps are slow in hashlink #607

Open
apxapob opened this issue Jul 14, 2023 · 1 comment
Open

Maps are slow in hashlink #607

apxapob opened this issue Jul 14, 2023 · 1 comment

Comments

@apxapob
Copy link

apxapob commented Jul 14, 2023

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.

@ncannasse
Copy link
Member

Thanks for the benchmark results, that's interesting indeed to see how both implementations are scaling wrt large number of elements. I think it would be better first to benchmark IntMaps to factor our String allocation and hashing, but I agree that the benchmark result might be related to the current implementation of maps, here:
https://github.com/HaxeFoundation/hashlink/blob/master/src/std/maps.h

I wonder what kind of structure is used on JS VM and how it compares also in terms of memory usage.

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

No branches or pull requests

2 participants