Faster StringMap iterators

118 views
Skip to first unread message

Joshua Granick

unread,
Feb 23, 2015, 10:55:42 AM2/23/15
to haxe...@googlegroups.com
Hey guys, saw this online:

http://blog.zame-dev.org/fast-iterators-for-stringmap/

Might be worth checking before the release. On the same topic, what's with the "terrible Flash for loop iterator" performance I always hear about, and garbage collection issues? Has this been addressed for Haxe 3.2 as well? I'd hate for "for" to be silently costly

Thanks!

Simon Krajewski

unread,
Feb 23, 2015, 10:58:39 AM2/23/15
to haxe...@googlegroups.com
I don't understand why anyone would go through the trouble of writing
such an article without checking the latest version first. StringMap on
JS and Flash has seen massive improvements on the development branch.

Simon

Simon Krajewski

unread,
Feb 23, 2015, 11:37:07 AM2/23/15
to haxe...@googlegroups.com
Am 23.02.2015 um 16:55 schrieb Joshua Granick:
Never mind, he actually mentions it.

Simon

Hugh

unread,
Feb 23, 2015, 11:15:52 PM2/23/15
to haxe...@googlegroups.com
There are some things you could do in the cpp target.  Currently is copies all the keys to an array, and then iterates over these, which is sub-optimal if you want to stop early.
This has an advantage in that array iterations are optimized, but mainly that it is not clear to me what precautions need to be taken for insertions/deletions while iterating.

Hugh

Sven Bergström

unread,
Feb 24, 2015, 6:14:27 AM2/24/15
to haxe...@googlegroups.com
In my cases I found that shielding map iterator with a simple length check gave me a huge bump in performance on c++ target:

//manually track this - not ideal but better than slower code
if(items_length > 0) {
   
for(thing in items) ..
}

It seems it could do this implicitly - and potentially not allocate an iterator at all (if possible) if it's empty;
At the time (while testing hxscout) I noticed that the only GC activity that I can see in my framework came from maps iterating over nothing.

I hadn't checked it after that, as Hugh was busy working on maps on git already for performance,
But I hope there's something we can do about that for subsequent updates, let me know what to do to help.

Viachaslau Tratsiak

unread,
Feb 24, 2015, 7:42:31 AM2/24/15
to haxe...@googlegroups.com
Probably it can return static empty iterator ( I just updated lib to show this idea - https://github.com/restorer/zame-haxe-miscutils/blob/master/org/zamedev/lib/FastIteratingStringMap.hx#L160 )

Viachaslau Tratsiak

unread,
Feb 24, 2015, 7:59:54 AM2/24/15
to haxe...@googlegroups.com
> what precautions need to be taken for insertions/deletions while iterating
In my point of view, it is UB, but still we can look how this is handled for HashMap in java ( openjdk version - http://grepcode.com/file_/repository.grepcode.com/java/root/jdk/openjdk/8-b132/java/util/HashMap.java/?v=source ) or even in haxe/std/java/_std/haxe/ds/StringMap.hx or in haxe/std/cs/_std/haxe/ds/StringMap.hx

P.S. anyone knows why std lib for java use it own HashMap implementation instead of using standard java.util.HashMap (same question for C#)?

Andreas Mokros

unread,
Feb 24, 2015, 1:02:47 PM2/24/15
to haxe...@googlegroups.com
Hi.

On Mon, 23 Feb 2015 16:58:34 +0100
Simon Krajewski <si...@haxe.org> wrote:
> StringMap on
> JS and Flash has seen massive improvements on the development branch.

The implementation makes sense. At least I can't think of a better
way to handle those damn inherited object properties ;-)

But is it really necessary to inline set, get and exists? It might
be nice to be able to extend it for an OrderedStringMap e.g.

And does inlining new() actually make a difference (on JS at least?)

--
Mockey
Reply all
Reply to author
Forward
0 new messages