docs(portmap): correct the recycle-check cost - it is elevation-bound, not ~180 ms#42
Merged
Merged
Conversation
The deferred "resolver refresh is ~180 ms/rebuild" follow-up did not reproduce
elevated. Measured 2026-07-24 (Win11, CPython 3.14, Chrome open), elevated and
non-elevated (runas /trustlevel): create_time() is ~0.005 ms per PID when
OpenProcess succeeds and ~5.7 ms when it is DENIED (psutil then scans the whole
system for that one PID). Denial is an elevation question, not the "hardened
process / Chrome renderer" one the older note assumed - renderers do not own
sockets, so they never reach this loop.
- elevated: 0 of 27 socket PIDs denied, warm recycle check ~0.16 ms, cold
resolve('chrome') ~36 ms
- non-elevated: 16 of 27 denied, ~90-180 ms warm, ~381 ms cold (this is where the
handoff's numbers came from)
Real impairment always runs elevated (WinDivert needs admin), so the check is
cheap in every real session; the only non-elevated path that runs the resolver is
--simulate. Batching the denied PIDs via NtQuerySystemInformation was measured and
rejected: it speeds only the non-elevated demo path and nothing else. Two docstrings
had drifted apart (_psutil_created said 0.005 ms, info said ~5 ms) - both were right
for a different elevation; now stated once, accurately. Docs only, no behaviour
change, so CHANGELOG.md is untouched.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
The socket-layer work left a deferred perf follow-up: "resolver refresh is ~180 ms/rebuild (create_time recycle check)", with a plan to batch the create-times in one syscall. Before building that, I measured it — and the premise does not hold under the conditions that matter.
Measured 2026-07-24 (Win11, CPython 3.14, Chrome open), elevated and non-elevated (
runas /trustlevel:0x20000):--simulateon non-admin)resolve('chrome')The cost of
create_time()is decided by one thing: whetherOpenProcesssucceeds — ~0.005 ms when it does, ~5.7 ms when it's denied (psutil then scans the whole system for that one PID). Denial is an elevation question, not the "hardened process / Chrome renderer" one the old note assumed — renderers don't own sockets, so they never reach this loop. The handoff's ~365/180 ms was measured non-elevated; my 381 ms non-elevated cold matches it.Real impairment always runs elevated — WinDivert won't open without admin, so a non-admin START fails outright. So the recycle check is already cheap (0.16 ms warm / 36 ms cold) in every real session. The only non-elevated path that runs the resolver at all is
--simulate(synthetic packets; the cost sits on the resolver thread, never the capture one).Two docstrings had drifted apart —
_psutil_createdclaimed 0.005 ms,infoclaimed ~5 ms — and each was right for a different elevation. This states it once, accurately.Changes
_psutil_createdandPortTable.infodocstrings inbeantester/portmap.py, and the matching PROJECT_NOTES line (in the private Doc repo, not this PR).NtQuerySystemInformationwas measured and rejected — it speeds only the non-elevated--simulatewarm check, does nothing for the elevated hot path, and nothing for the cold resolve (which name resolution dominates, notcreate_time). Written down so the next session doesn't re-open it.Reviewer notes
CHANGELOG.mdline: nothing a user notices (pure prose). Documented inCHANGELOG-INTERNAL.md, which also closes the "known perf follow-up" notes in two earlier entries.tests/test_processes.py, the recycle-protection suite) still passes (31/31), and no test pinned the old prose.Checklist
python -m pytest testspasses locally. (tests/test_processes.py31/31; docs-only change, no code path touched.)tests/for the style). (No behaviour change — docstring/notes correction only.)lang/en.jsonandlang/pl.jsonupdated. (No UI text.)CHANGELOG.md; technical ones and new tests inCHANGELOG-INTERNAL.md, under[Unreleased]. (Internal-only, nothing a user notices.)type(scope): summary).VERSION.txt.🤖 Generated with Claude Code