orthonym.runtime_tuning#

Note

Internal API. Names and behaviour may change between releases.

Process-level tuning for batch naming workers (perf lever A1 + A11, 2026-09-13).

Two knobs, both invisible to the names and tiers the engine emits:

  • Python cyclic GC. Naming allocates millions of small objects per molecule (RDKit wrappers, tuples, dicts). With the default thresholds (700, 10, 10) the collector runs every ~700 net allocations and rescans the long-lived module data each time it reaches generation 2. Measured on 100 fixed-seed molecules, one core, twice each (2026-09-12): default 36.3 s; gc.freeze + threshold (50_000, 20, 20) 31.8 s (-12 %); freeze + gc.disable 30.1 s (-17 %). Names identical in every mode. RSS grew LESS with the collector frozen (+42 MB vs +185 MB over 150 molecules), because the growth is lexicon warm-up, not garbage. The collector stays ON here (high threshold) so a 16,000-molecule shard cannot accumulate cyclic garbage unbounded.

  • BLAS/OpenMP thread pools. numpy’s bundled OpenBLAS spawns one thread per CPU (59 threads per worker on this 60-vCPU host, 2,400 across a 41-worker run). They are not idle: they spin when they start, so orthonym CCO used 10.8 s of user CPU for 2.2 s of wall time, and 3.2 s with one thread (2026-11-02). One thread is the right size for a process that never calls BLAS in parallel. The variables work only when set before numpy loads: import orthonym does not load numpy, and the CLI calls limit_blas_threads() first (a library user’s environment is left alone).

Opt-in. The repo’s batch runners (eval/harness.py, scripts/perf/name_sample.py) call tune_batch_process() explicitly; any other runner sets ORTHONYM_GC_TUNE=on and the first Orthonym constructed in the process applies it via maybe_tune_from_env(). ORTHONYM_GC_TUNE=off disables both paths (A/B runs). A library user who imports orthonym and never sets the variable is untouched.

orthonym.runtime_tuning.tune_batch_process(threshold=(50000, 20, 20), *, freeze=True, blas_threads=1)#

Apply the batch-worker tuning once per process. Returns True if applied (now or earlier), False if ORTHONYM_GC_TUNE=off. Idempotent; safe to call per molecule.

orthonym.runtime_tuning.limit_blas_threads()#

One BLAS/OpenMP thread for this process unless the user set the variables; call before numpy loads.

orthonym.runtime_tuning.maybe_tune_from_env()#

Apply:func:tune_batch_process iff ORTHONYM_GC_TUNE is on/1/true.

orthonym.runtime_tuning.is_tuned()#