Skip to content

Commit 8b9bf62

Browse files
dkukuclaude
andcommitted
Reduce memory usage in IEx autocomplete module listing
Use :erlang.loaded/0 instead of :code.all_loaded/0 since we only need module names, not file paths. The latter copies the full path for every loaded module, which on production systems with many dependencies caused significant memory spikes (measured 2.8MB -> 172KB on a real pod). Also replace Enum.sort/1 |> Enum.dedup/1 with :lists.usort/1 to eliminate one intermediate list allocation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6fd161d commit 8b9bf62

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

lib/iex/lib/iex/autocomplete.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,7 @@ defmodule IEx.Autocomplete do
604604

605605
defp match_modules(hint, elixir_root?) do
606606
get_modules(elixir_root?)
607-
|> Enum.sort()
608-
|> Enum.dedup()
607+
|> :lists.usort()
609608
|> Enum.drop_while(&(not String.starts_with?(&1, hint)))
610609
|> Enum.take_while(&String.starts_with?(&1, hint))
611610
end
@@ -615,7 +614,7 @@ defmodule IEx.Autocomplete do
615614
end
616615

617616
defp get_modules(false) do
618-
modules = Enum.map(:code.all_loaded(), &Atom.to_string(elem(&1, 0)))
617+
modules = Enum.map(:erlang.loaded(), &Atom.to_string/1)
619618

620619
case :code.get_mode() do
621620
:interactive -> modules ++ get_modules_from_applications()

0 commit comments

Comments
 (0)