On Fri, 19 Mar 2021 04:43:25 -0700
Rich Cavanaugh <[email protected]> wrote:

> When reviewing code I’d certainly have to read more carefully seeing
> something equivalent to `{current_value, current_value}` than I would
> `:keep`

Yes, this is also a very good point.


On Fri, 19 Mar 2021 12:30:41 +0100
José Valim <[email protected]> wrote:

> Can you please provide an example of where you think this would be
> optimized? I am certain for keyword it won't make a large difference
> because the cost is in traversing the keyword. And for maps, usually
> there is no update if you are trying to put the same value back, so I
> would say those concerns are already handled within the runtime.

I had to implement it to see it. I knew it would be optimised for
keyword lists, because we would be saving reversing the accumulator when
then list is long and the key is at the end of the list (worst case
scenario).

The results took me by surprise for Maps.
Benchmark results.
- map:
https://gist.github.com/eksperimental/77d5c67427fed0a8a9e7eee21219febb
- keyword:
https://gist.github.com/eksperimental/1bac29e80fd8329940be2cc8e6b86d52

This is the repository for the benchmarks
https://github.com/eksperimental/benchmark_keep

and this is the implementation in Elixir that passes all the tests,
https://github.com/eksperimental/elixir/tree/keep
 


-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/6058b1ae.1c69fb81.803d0.9a4cSMTPIN_ADDED_MISSING%40gmr-mx.google.com.

Reply via email to