From 8e497841fcec8a806285448a56215f94088244d5 Mon Sep 17 00:00:00 2001 From: Indrek Juhkam Date: Fri, 25 Oct 2019 06:46:08 +0300 Subject: [PATCH] Improve random_ref() function performance (#130) This is called each time there's a join or other kind of update. This is based on elixir plug [request id][1]. [1]: https://github.com/elixir-plug/plug/issues/629 --- lib/phoenix/tracker/shard.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/phoenix/tracker/shard.ex b/lib/phoenix/tracker/shard.ex index 27956caa1..4c5272f8c 100644 --- a/lib/phoenix/tracker/shard.ex +++ b/lib/phoenix/tracker/shard.ex @@ -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