$ the-wire · showcase
Algorithm L replaces inside-out shuffles in Enum
By RepoJournal · Filed · About Elixir & Phoenix · Composed from the cited sources · methodology
José Valim rewrote Enum.take_random/2 and Enum.shuffle/1, dropping the random-access inside-out shuffle and the keysort-with-random-keys approach in favor of Algorithm L and :rand.shuffle/1, with the biggest gains on lists.
Use batched Algorithm L in Enum.take_random/2 elixir-lang/elixir
The three separate clauses (count == 1, count <= 128, larger) collapse into a single reduce: the first `count` elements are prepended to a list, then Algorithm L computes how many elements to skip before each replacement. Every enumerable now takes the same path instead of requiring random access per element.
Traverse lists directly in Enum.take_random/2 elixir-lang/elixir
Lists get a dedicated recursive loop that keeps the skip count and reservoir as two separate arguments rather than a reduce accumulator, so skipped elements no longer allocate. The remaining implementation is still shared with other enumerables.
Use :rand.shuffle/1 for Enum.shuffle/1 elixir-lang/elixir
Enum.shuffle/1 now calls :rand.shuffle/1 directly on Erlang/OTP 29+, with a copy of that implementation in elixir_utils on OTP 27 and 28. The commit reports a 37 ns to 36 ns median on a single-element list, so this is a correctness and code-ownership change more than a speedup.