Hacker News new | ask | show | jobs
by Quekid5 1654 days ago
That particular example seems to be a horrible misapplication of an ImmutableMap. That's not a map, that's just a record of values. (Well the 'board' member is a collection, but you get what I'm saying.)

I'm not surprised you saw huge speed up... I mean the original is looking up record fields by their name at runtime. That's bound to be extremely slow because it's basically impenetrable to the JIT optimizer.

In this case doing it the "immutable way" would be to create a data object, freeze it, instead only creating copies (themselves frozen) with individual fields changes as appropriate.

I do wonder how it would have performed if you'd removed the outer 'sx', 'sy', 'board' map layer and kept the 'board' as an ImmutableList (or whatever).