Skip to content

Commit

Permalink
Improve random_ref() function performance (phoenixframework#130)
Browse files Browse the repository at this point in the history
This is called each time there's a join or other kind of update.

This is based on elixir plug [request id][1].

[1]: elixir-plug/plug#629
  • Loading branch information
indrekj authored and chrismccord committed Oct 25, 2019
1 parent f27f017 commit 8e49784
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/phoenix/tracker/shard.ex
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,13 @@ defmodule Phoenix.Tracker.Shard do
end

defp random_ref() do
:crypto.strong_rand_bytes(8) |> Base.encode64()
binary = <<
System.system_time(:nanosecond)::32,
:erlang.phash2({node(), self()}, 16_777_216)::16,
:erlang.unique_integer()::16
>>

Base.encode64(binary, padding: false)
end

defp log(%{log_level: false}, _msg_func), do: :ok
Expand Down

0 comments on commit 8e49784

Please sign in to comment.