4 ms·
Nice post! I enjoyed it. I don't understand why Html.Lazy uses referential equality instead of equality. In a language like Elm shouldn't they be the same? Wha
by truculent 5y ago
Nice post! I enjoyed it.
I don't understand why Html.Lazy uses referential equality instead of equality. In a language like Elm shouldn't they be the same? What potential bugs would using equality introduce?
Thanks
- masklinn 5y agoFrom what I understand it's Html.Styled.Lazy (from elm-css) which uses referential equality, possibly because it defines its own vdom in order to integrate styling information.
- truculent 5y agoI think it is both. In the process of confirming, I think I found the answer within the Elm docs[0]: > Note: When are two values “the same” though? To optimize for performance, we use JavaScript’s === operator behind the scenes > ... > Using reference equality is always cheap O(1), even when the data structure has thousands or millions of entries. So this is mostly about making sure that using lazy will never slow your code down a bunch by accident. All the checks are super cheap! It's not as elegant but you'd only ever use Html.Lazy for performance, so this trade-off seems to make perfect sense. [0]: https://guide.elm-lang.org/optimization/lazy.html https://guide.elm-lang.org/optimization/lazy.html
- Skinney 5y agoAuthor here. It’s both. Html.Styled is converted to regular Html when run, meaning it uses «normal» Html.Lazy under the hood.