Skip to content

perf: avoid sysinfo System::new_all() when only one metric is needed#46

Merged
ShixiangWang merged 1 commit into
Traitome:mainfrom
andrewbudge:perf/avoid-sysinfo-new-all
Jun 22, 2026
Merged

perf: avoid sysinfo System::new_all() when only one metric is needed#46
ShixiangWang merged 1 commit into
Traitome:mainfrom
andrewbudge:perf/avoid-sysinfo-new-all

Conversation

@andrewbudge

@andrewbudge andrewbudge commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

What

WorkflowConfig::validate() called sysinfo::System::new_all() — which walks all of /proc (every process, disk, and network interface) — just to read total system memory. That added a fixed ~50 ms to every parse / validate / dry-run / run.

Fix: probe only memory with System::new() + refresh_memory(). Behavior is identical — total_memory() still returns bytes in sysinfo 0.38, so the /1024/1024 math and the emitted warnings are unchanged. The same pattern is fixed in executor::available_memory_gb, available_threads (now num_cpus::get()), and process::detect_total_memory_mb.

How I found it

Running the existing criterion suite, parse/10_simple and parse/1000_simple both clocked ~50 ms — flat, regardless of rule count — while dag/chain_10000 built 10,000 rules in 3 ms. A fixed cost that didn't scale with the workload pointed straight at the per-call new_all().

Result

Bench Before After
parse/10_simple 50.0 ms 38.6 µs
parse/1000_simple 55.1 ms 1.52 ms
lifecycle/10_simple 107 ms 67.4 µs

Parsing now scales with rule count instead of being pinned at ~50 ms.

cargo fmt --check + cargo clippy --workspace -D warnings clean; cargo test --workspace --lib → 890 passed.

@andrewbudge
andrewbudge marked this pull request as draft June 17, 2026 18:38
Found via the criterion suite: parse/10_simple and parse/1000_simple both
cost a flat ~50ms, while the DAG engine builds 10,000 rules in 3ms. A fixed
cost independent of workload size pointed at WorkflowConfig::validate(),
which called sysinfo::System::new_all() — walking all of /proc (every
process, disk, and NIC) — just to read total system memory.

Probe only RAM with System::new() + refresh_memory(). total_memory() still
returns bytes in sysinfo 0.38, so behavior is unchanged. Same fix applied to
executor::available_memory_gb, available_threads (now num_cpus::get()), and
process::detect_total_memory_mb.

parse/10_simple: 50ms -> 39us. All 890 lib tests pass; fmt + clippy clean.
@andrewbudge
andrewbudge force-pushed the perf/avoid-sysinfo-new-all branch from d315337 to ef9d802 Compare June 17, 2026 18:40
@andrewbudge
andrewbudge marked this pull request as ready for review June 17, 2026 18:45
@ShixiangWang

Copy link
Copy Markdown
Member

@andrewbudge Great! thanks for the improvement and contribution.

@ShixiangWang
ShixiangWang merged commit 4b8d691 into Traitome:main Jun 22, 2026
7 checks passed
@andrewbudge
andrewbudge deleted the perf/avoid-sysinfo-new-all branch June 23, 2026 05:13
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.

2 participants