Skip to content

⚡ Cache hardware detection and optimize disk loop - #412

Open
Cylae wants to merge 1 commit into
mainfrom
perf/cache-hardware-detection-17336695570065704145
Open

⚡ Cache hardware detection and optimize disk loop#412
Cylae wants to merge 1 commit into
mainfrom
perf/cache-hardware-detection-17336695570065704145

Conversation

@Cylae

@Cylae Cylae commented Sep 9, 2026

Copy link
Copy Markdown
Owner

💡 What:

  • Added a thread-safe static cache (static HARDWARE_CACHE: OnceLock<HardwareInfo>) for HardwareInfo::detect(), while moving uncached physical system hardware detection into HardwareInfo::detect_uncached().
  • Optimized the virtual filesystem disk calculation loop using byte-slice pattern matching (b"overlay" | b"tmpfs" | ...) and functional iterator summation, eliminating std::str::from_utf8 validation overhead.
  • Added a Criterion benchmark benchmark_hardware_detection to server_manager/benches/service_benchmark.rs.
  • Added unit test test_hardware_info_cached_and_uncached_detection in server_manager/src/core/hardware.rs.

🎯 Why:
HardwareInfo::detect() was repeatedly invoked when composing structures, generating configurations, and executing CLI/web operations. Executing System::new(), refreshing disk/CPU lists, searching PATH binaries via which, and parsing user contexts on every call created significant latency. Caching static hardware information and removing string conversions makes hardware detection near-instantaneous.

📊 Measured Improvement:

  • Baseline (HardwareInfo::detect() uncached): 496.01 µs (microseconds)
  • Optimized (HardwareInfo::detect() cached): 45.858 ns (nanoseconds)
  • Performance Boost: -99.991% execution time reduction (~10,800x speedup)

PR created automatically by Jules for task 17336695570065704145 started by @Cylae

Cache HardwareInfo::detect result using std::sync::OnceLock to avoid
repeated expensive system information detection calls. Optimize virtual
filesystem filtering in disk summation loop using byte slice matching.
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant