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

Breaking changes; Semigroup, union #11

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

drathier
Copy link
Contributor

@drathier drathier commented Sep 24, 2022

Breaking changes:

  • Unbiased semigroup (was right-biased, Data.Map was left-biased and is now unbiased)
  • Left-biased union (was right-biased before, Data.Map was/is left-biased)
  • Fold iteration order is now deterministic

Based on #10

@FredTheDino
Copy link

I did some measurements. It looks like it performs well. But the sort is surprisingly slow. I peaked some at the sort implementation, and it just looks like nonsense to me, but I'm no Erlang-god. https://github.com/erlang/otp/blob/master/lib/stdlib/src/lists.erl#L507

Averaged over 100 runs. Time is in micro-seconds.

10000   Sorted: 73.36     Unsorted: 781.72
50000   Sorted: 550.77    Unsorted: 7825.56
100000  Sorted: 1750.4    Unsorted: 15605.6
500000  Sorted: 8101.75   Unsorted: 97175.44
1000000 Sorted: 13362.49  Unsorted: 193159.13

Collected using:

N = 1000000,
X = lists:seq(0,N),
F = fun() -> lists:sort(X) end,

Q = [Y||{_,Y} <- lists:sort([ {rand:uniform(), N} || N <- X])],
G = fun() -> lists:sort(Q) end,

TCN2 = fun(T,F,0) -> ok; (T,F,N) -> F(), T(T,F,N-1) end,
TCN = fun(F,N) -> B=now(), TCN2(TCN2,F,N), A=now(), timer:now_diff(A,B)/N end.

N.
"Sorted:".
TCN(F, 100).
"Unsorted:".
TCN(G, 100).

FredTheDino and others added 2 commits October 31, 2022 14:38
There are a few calling indirections, but I don't expect much
performance loss from this. Erlang usually handles functions pretty
well!

We went from this incorrect code:
```
foldMImpl(Bind, F, MZ, M) ->
    lists:foldl(fun (K, V, Acc) ->
        (Bind(Acc))(fun (Z) -> ((F(Z))(K))(V) end)
    end, MZ, lists:sort(maps:keys(M))).
```
To this:
```
foldM() -> fun (DictMonad) ->
  Bind@382 = (?MEMOIZE((control_bind@ps:bind(((maps:get('Bind1', DictMonad))(undefined)))))),
  Pure@383 = (?MEMOIZE((control_applicative@ps:pure(((maps:get('Applicative0', DictMonad))(undefined)))))),
  fun (F) ->
    fun (Z) ->
      fun (M) ->
        (foldl(fun (Acc) ->
          fun (K) ->
            fun (V) ->
              ((Bind@382(Acc))(fun (A) ->
                (((F(A))(K))(V))
              end))
            end
          end
        end, (Pure@383(Z)), M))
      end
    end
  end
end.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants