Skip to main content

prewarm_kpathsea

Function prewarm_kpathsea 

Source
pub fn prewarm_kpathsea()
Expand description

Force-initialize the kpathsea global state and warm up the per- format suffix tables.

Why: Kpaths::find_file lazily inits the kpse format-info table for each format type the first time a matching filename is looked up. The chain is find_file → guess_format_from_filename → kpathsea_init_format → kpathsea_init_db → kpathsea_cnf_get → hash_insert_normalized, taking ~30-40 ms total across the first dozen lookups. Profile data on 1910.01256 attributes ~3.5% of wall to that chain.

What this does: acquires the KPSE mutex once and runs a single find_file probe per common file format. Each probe guarantees kpathsea_init_format runs for that format type, so every subsequent real lookup hits the post-init fast path.

Concurrency: safe to invoke on a background thread spawned at process start. KPSE is process-global (Lazy<Mutex<…>>), so the init done on a background thread is visible to the main thread. The Mutex briefly serializes the prewarm against the main thread’s first real lookup, but dump load + arg parsing take >50 ms before digest reaches its first package resolution, by which point the prewarm is usually finished. Idempotent: re-entry while in flight is a no-op (lock contention only).