#1493·magika

CLI start pays about 1.5 ms for linking Metal even when it never uses the GPU

Author: eburszteinCreated Sep 25, 2026Updated Sep 25, 2026

On macOS the magika executable links Metal, CoreGraphics, CoreFoundation and libobjc, because tract-metal is a normal dependency of magika-tract-runtime. dyld loads and initializes them at every start, including for runs that never touch the GPU (--backend=cpu, --rules=only, --version).

Median of 60 interleaved runs of each command, Apple M-series:

command time
/usr/bin/true 1.91 ms
file --version (libmagic) 2.10 ms
#1447 build, runtime loaded as a plugin, --version 2.92 ms
current build, Metal linked, --version 4.45 ms

That is about 1.5 ms of every run. It matters for the claim that Magika is as fast as libmagic on small inputs: with #1492, a one-file --rules=only run is about 9 ms against 2.9 ms for file -b, and process start is the largest remaining fixed cost.

Options, to discuss before writing anything:

  • Load the GPU backend only when a run needs it. For example, a runtime plugin loaded with dlopen, as #1447 did (rust/runtime, rust/runtime-abi, rust/runtime-plugin). It costs native loading code and an ABI.
  • Keep Metal linked and accept the cost. Most runs that use the model load it anyway, and #1490 already hides GPU preparation behind the CPU.

Found while splitting #1447 (see its tracker comment). Not blocking.

Generated with Claude Code