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

ES6 Map vs. haxe.ds.ObjectMap #7349

Closed
jozefchutka opened this issue Aug 13, 2018 · 3 comments · Fixed by #11698
Closed

ES6 Map vs. haxe.ds.ObjectMap #7349

jozefchutka opened this issue Aug 13, 2018 · 3 comments · Fixed by #11698
Labels
platform-javascript Everything related to JS / JavaScript
Milestone

Comments

@jozefchutka
Copy link

jozefchutka commented Aug 13, 2018

Hi everyone,

what are the plans with using ES6 build in Map instead of haxe implementation of ObjectMap (and others). I tried to benchmark and compare these two, it seems the access time is similar but custom haxe implementation consumes 15%+ retained memory (in chrome).

Tested with following implementation:

@:multiType(@:followWithAbstracts K)
abstract Map2<K,V>(IMap<K,V>) {
    // ... copy of haxe.Map
    @:to static inline function toObjectMap<K:{ },V>(t:IMap<K,V>):IMap<{ },V> {
        return NativeMap.isSupported() ? new NativeMap<{ },V>() : new ObjectMap<{ }, V>();
    }
    // ... rest of haxe.Map
}

class NativeMap<K,V> implements haxe.Constraints.IMap<K,V> {
    var source:Dynamic;
    
    public function new(){
        source = untyped __js__('new Map()'); 
    }
    
    public static function isSupported():Bool{
        return Reflect.hasField(js.Browser.window, "Map");
    }
    
    public function get(k:K):Null<V>{
        return source.get(k);
    }
    
    public function set(k:K, v:V):Void{
        source.set(k, v);
    }
    // ...
}
@nadako
Copy link
Member

nadako commented Aug 13, 2018

Yeah, the plan is to implement ES6 Map-based haxe maps, hopefully I'll find time for Haxe 4.

@markknol markknol added the platform-javascript Everything related to JS / JavaScript label Sep 11, 2018
@Simn Simn added this to the Design milestone Dec 12, 2018
@Simn
Copy link
Member

Simn commented Jun 5, 2020

@nadako Could you remind me (again) what the outcome was here?

@nadako
Copy link
Member

nadako commented Jun 5, 2020

Well, I have a WIP PR #9303 that I have no time to work on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-javascript Everything related to JS / JavaScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants