Skip to content

perf(linux): the status parser finds each line's end with memchr, not a byte loop (#2980) - #3020

Merged
mgradwohl merged 1 commit into
mainfrom
perf/status-memchr-2980
Oct 26, 2026
Merged

mgradwohl merged 1 commit into
mainfrom
perf/status-memchr-2980

Conversation

@mgradwohl

Copy link
Copy Markdown
Owner

Description

Fixes #2980

LinuxProcessProbe's status parser (applyStatus()) found each line's end with a byte-at-a-time loop on every process, every sample. The issue's profile put that at about a tenth of the sampler's user-space CPU over many processes. It now uses std::memchr. Everything else stays as it was: the early exit once every field is found, the bounds, the whole-line rule for VmHWM, RssAnon, VmSwap and Cpus_allowed_list, numeric overflow checks, effective/real UID, and variable-width affinity. Every metric is still sampled at the Settings interval.

Measured on the same machine (WSL Ubuntu 26.04, 10 CPUs), the same benchmark-preset build, before and after the change, 10 repetitions of 0.5 s:

Benchmark Before (median, CV) After (median, CV) Change
BM_ProcessProbe_EnumerateSynthetic/5000 70.3 ms, 4.56% 65.3 ms, 1.63% −7.1%
BM_ProcessProbe_EnumerateSyntheticRebuild/5000 104 ms, 2.79% 98.2 ms, 1.20% −5.6%

As the issue notes, these fixtures model /proc with ordinary files on WSL2. The relative gain is the result here, not an absolute native-/proc budget, and parsing is one contributor to the 5,000-process cost, not all of it.

PR Size

✅ Small (5 lines).

Type of Change

  • Bug fix (non-breaking change that fixes an issue): performance

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the project's coding standards
  • I have run clang-tidy and addressed any warnings
  • I have run clang-format on my changes
  • All new and existing tests pass

Testing

The probe's existing tests cover the status parser's truncated lines, the cut-off affinity lists, VmHWM past the stack buffer and the UID cases. Full suite: 683/683.

Additional Notes

Performance PR: it merges only after Heavy Checks, including benchmark-regression, passes on its head.

🤖 Generated with Claude Code

… a byte loop (#2980)

The scan was about a tenth of the sampler's user-space CPU over many
processes. Same machine, same benchmark build, 10 repetitions of 0.5 s:
BM_ProcessProbe_EnumerateSynthetic/5000 70.3 -> 65.3 ms median (CV 4.6% ->
1.6%), ...SyntheticRebuild/5000 104 -> 98.2 ms (CV 2.8% -> 1.2%). The early
exit, the bounds and the truncated-line handling are as before.

Fixes #2980

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mgradwohl mgradwohl added this to the v0.10.0 milestone Oct 26, 2026
@mgradwohl mgradwohl added linux performance Platform agent:WSL Owned by the Linux/WSL Claude session (bug-fix conveyor) labels Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@mgradwohl
mgradwohl marked this pull request as ready for review October 26, 2026 05:42
@mgradwohl
mgradwohl merged commit c796b9b into main Oct 26, 2026
36 checks passed
@mgradwohl
mgradwohl deleted the perf/status-memchr-2980 branch October 26, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:WSL Owned by the Linux/WSL Claude session (bug-fix conveyor) linux performance Platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf] Linux status parsing scans each line byte by byte on every process sample

1 participant