From 36e700b08229dfee5f56d0a5dc436926fba9bb40 Mon Sep 17 00:00:00 2001 From: preciz Date: Sun, 30 Aug 2026 22:22:38 +0200 Subject: [PATCH] Optimize JSON map key encoding Inline the per-key dispatch to avoid a private function call for every encoded map entry. Assisted-by: Codex:GPT-5 --- lib/elixir/lib/json.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/elixir/lib/json.ex b/lib/elixir/lib/json.ex index d5daa3e6b9d..34e60f33944 100644 --- a/lib/elixir/lib/json.ex +++ b/lib/elixir/lib/json.ex @@ -175,6 +175,7 @@ defimpl JSON.Encoder, for: Map do # Erlang supports only numbers, binaries, and atoms as keys, # we support anything that implements the String.Chars protocol. + @compile inline: [key: 2] defp key(key, encoder) when is_atom(key), do: encoder.(Atom.to_string(key), encoder) defp key(key, encoder) when is_binary(key), do: encoder.(key, encoder) defp key(key, encoder), do: encoder.(String.Chars.to_string(key), encoder)