perf(libSceNetCtl): reuse host interface queries until Windows reports a change #9386
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9386"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by mehmetbayoglu on 2026-10-21T20:07:35Z.
What
On Windows,
sceNetCtlGetInfo,sceNetCtlGetState,sceNetCtlGetStateV6,sceNetCtlCheckCallback,sceNetCtlGetIfStatand the DNS servers libSceNet reads calledGetAdaptersAddresseson every call. It is slow (it goes through an RPC to the network service), and PPSA34501 (Call of Duty: Black Ops) callssceNetCtlGetInfooften enough that this took about a fifth of one thread at the Kino der Toten spawn.The answers are now kept per address family and for the IPv4 interface, and dropped when
NotifyUnicastIpAddressChange,NotifyIpInterfaceChangeorNotifyRouteChange2reports a change, so unplugging a cable or switching networks is still seen. If the notifications cannot be registered, every call queries the host as before. Linux and macOS are unchanged. The debt entry records the one gap: a change of DNS servers alone is picked up only at the next address, interface or route change.Tested
ctest -R "net_ctl|netctl"passes (3 tests).APS5_TRACE_SUMMARY_EVERY=10andAPS5_SAMPLE_THREADS, three runs each in the order main, change, change, main, main, change. Same executable on both sides; onlylibSceNetCtl.prxdiffers in code.IPHLPAPI.DLLonmain(17.9, 20.3, 19.0) and 0.0 % with the change (all three runs).main, 11.4 to 12.1 with the change). The GPU submission path, not this thread, limits the frame on this scene, so this is a CPU saving, not a frame rate gain.Summary lines (interval 40 to 50 s, in Kino),
mainthen the change:Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by mehmetbayoglu on 2026-10-21T20:08:07Z.
tools/trace_digest.pyoutput for every run (PPSA34501, Kino der Toten route, 70 s,APS5_TRACE_SUMMARY_EVERY=10), in the order they ran.mainis7202f120d5, the change is 0a5001bdec.run 2-main
7 intervals, 0.0 to 70.2 s, 1490 presents
NVIDIA GeForce RTX 4070 Ti, NVIDIA 617.42, Windows 10.0.26200, 1920x1080, commit
7202f120d5run 3-change
7 intervals, 0.0 to 70.2 s, 1492 presents
NVIDIA GeForce RTX 4070 Ti, NVIDIA 617.42, Windows 10.0.26200, 1920x1080, commit 0a5001bdecae
run 4-change
7 intervals, 0.0 to 70.1 s, 1502 presents
NVIDIA GeForce RTX 4070 Ti, NVIDIA 617.42, Windows 10.0.26200, 1920x1080, commit 0a5001bdecae
run 5-main
7 intervals, 0.0 to 70.3 s, 1490 presents
NVIDIA GeForce RTX 4070 Ti, NVIDIA 617.42, Windows 10.0.26200, 1920x1080, commit
7202f120d5run 6-main
7 intervals, 0.0 to 70.2 s, 1489 presents
NVIDIA GeForce RTX 4070 Ti, NVIDIA 617.42, Windows 10.0.26200, 1920x1080, commit
7202f120d5run 7-change
7 intervals, 0.0 to 70.2 s, 1486 presents
NVIDIA GeForce RTX 4070 Ti, NVIDIA 617.42, Windows 10.0.26200, 1920x1080, commit 0a5001bdecae
Thread samples (
APS5_SAMPLE_THREADS),IPHLPAPI.DLLinclusive samples summed over threads, as a share of one thread: main 17.9 %, 20.3 %, 19.0 %; change 0.0 % in all three runs.Imported from boykopovar/AnyPS5. Originally posted by mehmetbayoglu on 2026-10-21T23:59:10Z.
Checked both:
libSceNetCtl/Export.cpp. This PR changes only the Windows path (the query is renamed and cached under#ifdef _WIN32; Linux and macOS still query the host directly), so the two do not implement the same thing. Whichever lands second may need a small rebase aroundFindHostIpv4Interface.docs/dev/debt/libSceNetCtl.mdfor other entries, not the host interface cache.No dependency either way.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T06:22:24Z.
Review: COMMENTED
I reviewed the Windows cache path and the invalidation flow. The cache is guarded by a mutex, change notifications only advance an atomic generation, and each subsequent query refreshes cached address/interface state when that generation changes. If notification registration partially fails, the successful handles are cancelled and the code falls back to querying on every call, preserving correctness. The documented DNS-only invalidation gap matches the implementation.
I built
guest_net_ctl_testslocally on Linux. The target compiled and linked; its runtime could not execute here because the host CPU lacks the PS5-required LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA extensions. The PR's Windows title A/B measurements and focused Windows CTest results are useful evidence; I did not reproduce them locally. Local conventions andgit diff --checkboth pass.Before merge, please refresh this head against current
main(d6eafa54d0464258574fd2f71889754d05a5bc93; this branch is 481 commits behind). I confirmed the shared-file merge-tree with open #7201 has a realExport.cppconflict inlibSceNetCtl; the #7201 author’s note about resolving the nearbyFindHostIpv4Interfacechange is relevant. The merge-tree with #6039 also reports a conflict indocs/dev/debt/libSceNetCtl.md, so preserve both debt entries when rebasing even though the topics differ. Both PRs remain open. The title-specific PPSA34501 performance evidence is clear and satisfies the current named-title intake direction.Imported from boykopovar/AnyPS5. Originally posted by mehmetbayoglu on 2026-10-22T06:27:21Z.
@MarcZX10 Thanks for the review. Refreshed: the branch is rebased onto current
main(d6eafa54d0), now3f698c1016. The rebase applied cleanly and the change is identical, so the measurements in the description (taken at 0a5001bdec) still describe this head. After the rebase I rebuilt the libraries and reranguest_net_ctl,guest_netctl_apandguest_netctl_ap_dialogon Windows (all pass), plus the conventions check andgit diff --check.On #7201 and #6039: agreed, whichever lands second keeps both sides, the macOS routing-table lookup beside the cached Windows path in
Export.cpp, and both debt entries inlibSceNetCtl.md. I will do that rebase if this one is second.