Skip to content

Start :ssl, :inets and httpc lazily - #1300

Open
onnimonni wants to merge 1 commit into
hexpm:mainfrom
onnimonni:lazy-httpc
Open

onnimonni wants to merge 1 commit into
hexpm:mainfrom
onnimonni:lazy-httpc

Conversation

@onnimonni

Copy link
Copy Markdown

Closes #1295.

Every Mix command in a project with Hex deps starts Hex while converging deps. Hex started :ssl, :inets (+ :public_key, :crypto) and the :hex httpc profile even when nothing touches the network, e.g. a no-op mix compile.

Changes:

  • :ssl/:inets moved from extra_applications to included_applications: loaded and on the compile path (mix_hex_registry.erl includes public_key.hrl), but not started
  • Hex.HTTP.start_httpc/0 restores their code paths (Mix.ensure_application!/1, pruning), starts them and the :hex profile once per VM, on the first request. :persistent_term fast path, :global.trans/3 so concurrent registry fetches start it once
  • Removed the :ssl_version state, which was computed on start (needed :ssl loaded) and never read

Measured on macOS (Apple Silicon), OTP 30, Elixir 1.21.0-dev, fresh VM, median of 5:

Hex.start()
main 48ms
this PR 19ms

mix test --exclude integration passes locally (no hexpm checkout here). Checked mix hex.info, mix hex.outdated against hex.pm with the built archive.

Every Mix command in a project with Hex deps starts Hex, which started
:ssl, :inets and the :hex httpc profile even when nothing touches the
network. Start them on the first request instead.

Closes hexpm#1295.
Comment thread lib/hex/http.ex
# network don't pay for starting them
def start_httpc() do
unless :persistent_term.get({__MODULE__, :httpc_started}, false) do
:global.trans({{__MODULE__, :start_httpc}, self()}, &do_start_httpc/0, [node()])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The :global.trans lock isn't needed. Each step in do_start_httpc/0 is safe to repeat, so the :persistent_term check is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start :ssl/:inets lazily: ~20ms on every Mix command that loads Hex deps

2 participants