-
Notifications
You must be signed in to change notification settings - Fork 0
feat: show related processes, essentially deduplicating processes like witr but being more helpful #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…e witr but being more helpful
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe pull request refactors process discovery and inspection to support multiple matching processes. The Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Main
participant findMyProc
participant PIDinspect
participant Output
User->>Main: Request process inspection (process name)
Main->>findMyProc: findMyProc(process name)
findMyProc->>findMyProc: Enumerate all matching processes
findMyProc-->>Main: Return ProcInfos (names[], pids[])
alt Multiple matches found
Main->>PIDinspect: PIDinspect(pids[], names[])
PIDinspect->>Output: Primary process info
PIDinspect->>Output: "Related Processes" section
Output-->>User: Display all matching processes
else Single match found
Main->>PIDinspect: PIDinspect(pids[], names[])
PIDinspect->>Output: Process info
Output-->>User: Display process info
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
do you see a corellation between performance and the amount of related processes? Target: winlogon.exe
Process: winlogon.exe (pid 7108)
Executable Path: C:\Windows\System32\winlogon.exe
User: SYSTEM
Command: winlogon.exe {F481712C-B2EB-461C-81F2-3012146E0000}
Working Directory: C:\Windows\system32\
RAM Usage: 13 MB
Why It Exists:
winlogon.exe (PID 7108)
└─ fontdrvhost.exe (PID 5548)
└─ dwm.exe (PID 6816)
Started: 6 minutes ago (Tue 2026-02-10 21:16:24 +0000)
winlogon.exe check took 19.7111 ms
Target: lsass.exe
Process: lsass.exe (pid 992)
Executable Path: C:\Windows\System32\lsass.exe
User: SYSTEM
Command: C:\Windows\system32\lsass.exe
Working Directory: C:\Windows\system32\
RAM Usage: 31 MB
Why It Exists:
wininit.exe (PID 840)
└─ lsass.exe (PID 992)
Listening:
0.0.0.0:49664
Started: 6 minutes ago (Tue 2026-02-10 21:15:55 +0000)
lsass.exe check took 17.2429 ms
Target: win-witr.exe
Process: win-witr.exe (pid 16984)
Executable Path: D:\a\win-witr\win-witr\win-witr.exe
User: runneradmin
Command: "D:\a\win-witr\win-witr\win-witr.exe" win-witr.exe
Working Directory: D:\a\win-witr\win-witr\
RAM Usage: 5 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ svchost.exe (PID 2592)
└─ hosted-compute-agent (PID 2316)
└─ Runner.Listener.exe (PID 2196)
└─ Runner.Worker.exe (PID 2384)
└─ pwsh.exe (PID 2664)
└─ win-witr.exe (PID 16984)
Started: 0 seconds ago (Tue 2026-02-10 21:22:25 +0000)
win-witr.exe check took 22.704 ms
Target: wininit.exe
Process: wininit.exe (pid 840)
Executable Path: C:\Windows\System32\wininit.exe
User: SYSTEM
Command: Failed to Access (wwitr:procParamPtrRead)
Working Directory: Failed to Access (wwitr:procParamPtrRead)
RAM Usage: 9 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ LsaIso.exe (PID 984)
└─ lsass.exe (PID 992)
└─ fontdrvhost.exe (PID 692)
Listening:
0.0.0.0:49665
Started: 6 minutes ago (Tue 2026-02-10 21:15:54 +0000)
wininit.exe check took 17.9456 ms
Target: explorer.exe
Process: explorer.exe (pid 8132)
Executable Path: C:\Windows\explorer.exe
User: runneradmin
Command: C:\Windows\Explorer.EXE
Working Directory: C:\Windows\system32\
RAM Usage: 162 MB
Why It Exists:
explorer.exe (PID 8132)
└─ AzureArcSysTray.exe (PID 10148)
└─ ServiceFabricLocalClusterManager.exe (PID 4888)
Started: 5 minutes ago (Tue 2026-02-10 21:16:29 +0000)
explorer.exe check took 19.0409 ms
Error: Unable to query executable path. Error code: 31
Maybe Access is Denied or the process is running entirely in RAM.
Target: Registry
Process: Registry (pid 136)
Hint: This error indicates a driver error, but in win-witr, it often means you are calling a pseudo-process, such as System, Registry, or other processes that only exist in RAM as a kernel process. It is often easy to tell them apart if they lack a .exe extension.
User: SYSTEM
Command: Failed to Access (wwitr:procParamPtrRead)
Working Directory: Failed to Access (wwitr:procParamPtrRead)
RAM Usage: 41 MB
Why It Exists:
Registry (PID 136)
Started: 6 minutes ago (Tue 2026-02-10 21:15:44 +0000)
Registry check took 21.8237 ms
Target: csrss.exe
Process: csrss.exe (pid 744)
Executable Path: C:\Windows\System32\csrss.exe
User: SYSTEM
Command: Failed to Access (wwitr:procParamPtrRead)
Working Directory: Failed to Access (wwitr:procParamPtrRead)
RAM Usage: 6 MB
Why It Exists:
csrss.exe (PID 744)
Started: 6 minutes ago (Tue 2026-02-10 21:15:52 +0000)
Related Processes:
csrss.exe (PID 6984)
csrss.exe check took 19.7862 ms
Target: fontdrvhost.exe
Process: fontdrvhost.exe (pid 692)
Executable Path: C:\Windows\System32\fontdrvhost.exe
User: UMFD-0
Command: "fontdrvhost.exe"
Working Directory: C:\Windows\system32\
RAM Usage: 4 MB
Why It Exists:
wininit.exe (PID 840)
└─ fontdrvhost.exe (PID 692)
Started: 6 minutes ago (Tue 2026-02-10 21:15:57 +0000)
Related Processes:
fontdrvhost.exe (PID 5548)
fontdrvhost.exe check took 19.3926 ms
Target: svchost.exe
Process: svchost.exe (pid 808)
Executable Path: C:\Windows\System32\svchost.exe
User: SYSTEM
Command: C:\Windows\system32\svchost.exe -k DcomLaunch -p
Working Directory: C:\Windows\system32\
RAM Usage: 34 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ svchost.exe (PID 808)
└─ WmiPrvSE.exe (PID 6464)
└─ SearchHost.exe (PID 8700)
└─ StartMenuExperienceHost.exe (PID 8720)
└─ RuntimeBroker.exe (PID 8840)
└─ UserOOBEBroker.exe (PID 8572)
└─ OpenConsole.exe (PID 2528)
└─ WindowsTerminal.exe (PID 9688)
└─ RuntimeBroker.exe (PID 1704)
└─ WmiPrvSE.exe (PID 2908)
└─ TiWorker.exe (PID 8792)
Started: 6 minutes ago (Tue 2026-02-10 21:15:57 +0000)
Related Processes:
svchost.exe (PID 1084)
svchost.exe (PID 1128)
svchost.exe (PID 1320)
svchost.exe (PID 1328)
svchost.exe (PID 1468)
svchost.exe (PID 1528)
svchost.exe (PID 1568)
svchost.exe (PID 1620)
svchost.exe (PID 1628)
svchost.exe (PID 1636)
svchost.exe (PID 1652)
svchost.exe (PID 1684)
svchost.exe (PID 1924)
svchost.exe (PID 1072)
svchost.exe (PID 2056)
svchost.exe (PID 2188)
svchost.exe (PID 2276)
svchost.exe (PID 2320)
svchost.exe (PID 2328)
svchost.exe (PID 2396)
svchost.exe (PID 2420)
svchost.exe (PID 2552)
svchost.exe (PID 2584)
svchost.exe (PID 2592)
svchost.exe (PID 2616)
svchost.exe (PID 2636)
svchost.exe (PID 2644)
svchost.exe (PID 2732)
svchost.exe (PID 2756)
svchost.exe (PID 2840)
svchost.exe (PID 2944)
svchost.exe (PID 2952)
svchost.exe (PID 3012)
svchost.exe (PID 2920)
svchost.exe (PID 3092)
svchost.exe (PID 3124)
svchost.exe (PID 3196)
svchost.exe (PID 3232)
svchost.exe (PID 3284)
svchost.exe (PID 3344)
svchost.exe (PID 3472)
svchost.exe (PID 3488)
svchost.exe (PID 3504)
svchost.exe (PID 3516)
svchost.exe (PID 3540)
svchost.exe (PID 3704)
svchost.exe (PID 3748)
svchost.exe (PID 3776)
svchost.exe (PID 3852)
svchost.exe (PID 3864)
svchost.exe (PID 3884)
svchost.exe (PID 3972)
svchost.exe (PID 4032)
svchost.exe (PID 4072)
svchost.exe (PID 4828)
svchost.exe (PID 4316)
svchost.exe (PID 4320)
svchost.exe (PID 5512)
svchost.exe (PID 5892)
svchost.exe (PID 7136)
svchost.exe (PID 7560)
svchost.exe (PID 7776)
svchost.exe (PID 8060)
svchost.exe (PID 7184)
svchost.exe (PID 1480)
svchost.exe (PID 8532)
svchost.exe (PID 8900)
svchost.exe (PID 8432)
svchost.exe (PID 9788)
svchost.exe (PID 10072)
svchost.exe (PID 10044)
svchost.exe (PID 10008)
svchost.exe (PID 7176)
svchost.exe (PID 3392)
svchost.exe (PID 5744)
svchost.exe (PID 736)
svchost.exe (PID 6180)
svchost.exe (PID 6568)
svchost.exe check took 125.6466 ms
Target: smss.exe
Process: smss.exe (pid 512)
Executable Path: C:\Windows\System32\smss.exe
User: SYSTEM
Command: Failed to Access (wwitr:procParamPtrRead)
Working Directory: Failed to Access (wwitr:procParamPtrRead)
RAM Usage: 1 MB
Why It Exists:
smss.exe (PID 512)
Started: 6 minutes ago (Tue 2026-02-10 21:15:46 +0000)
smss.exe check took 18.6065 ms
Target: services.exe
Process: services.exe (pid 964)
Executable Path: C:\Windows\System32\services.exe
User: SYSTEM
Command: Failed to Access (wwitr:procParamPtrRead)
Working Directory: Failed to Access (wwitr:procParamPtrRead)
RAM Usage: 11 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ svchost.exe (PID 808)
└─ svchost.exe (PID 1084)
└─ svchost.exe (PID 1128)
└─ svchost.exe (PID 1320)
└─ svchost.exe (PID 1328)
└─ svchost.exe (PID 1468)
└─ svchost.exe (PID 1528)
└─ svchost.exe (PID 1568)
└─ svchost.exe (PID 1620)
└─ svchost.exe (PID 1628)
└─ svchost.exe (PID 1636)
└─ svchost.exe (PID 1652)
└─ svchost.exe (PID 1684)
└─ svchost.exe (PID 1924)
└─ vmms.exe (PID 1976)
└─ svchost.exe (PID 1072)
└─ svchost.exe (PID 2056)
└─ svchost.exe (PID 2188)
└─ svchost.exe (PID 2276)
└─ svchost.exe (PID 2320)
└─ svchost.exe (PID 2328)
└─ svchost.exe (PID 2396)
└─ svchost.exe (PID 2420)
└─ svchost.exe (PID 2552)
└─ svchost.exe (PID 2584)
└─ svchost.exe (PID 2592)
└─ svchost.exe (PID 2616)
└─ svchost.exe (PID 2636)
└─ svchost.exe (PID 2644)
└─ svchost.exe (PID 2732)
└─ svchost.exe (PID 2756)
└─ svchost.exe (PID 2840)
└─ svchost.exe (PID 2944)
└─ svchost.exe (PID 2952)
└─ svchost.exe (PID 3012)
└─ svchost.exe (PID 2920)
└─ svchost.exe (PID 3092)
└─ svchost.exe (PID 3124)
└─ svchost.exe (PID 3196)
└─ svchost.exe (PID 3232)
└─ svchost.exe (PID 3284)
└─ svchost.exe (PID 3344)
└─ spoolsv.exe (PID 3352)
└─ svchost.exe (PID 3472)
└─ svchost.exe (PID 3488)
└─ svchost.exe (PID 3504)
└─ svchost.exe (PID 3516)
└─ svchost.exe (PID 3540)
└─ dockerd.exe (PID 3676)
└─ svchost.exe (PID 3704)
└─ svchost.exe (PID 3748)
└─ SMSvcHost.exe (PID 3760)
└─ svchost.exe (PID 3776)
└─ WaAppAgent.exe (PID 3800)
└─ mqsvc.exe (PID 3808)
└─ sqlwriter.exe (PID 3816)
└─ svchost.exe (PID 3852)
└─ svchost.exe (PID 3864)
└─ sshd.exe (PID 3872)
└─ svchost.exe (PID 3884)
└─ WindowsAzureGuestAgent.exe (PID 3956)
└─ svchost.exe (PID 3972)
└─ svchost.exe (PID 4032)
└─ svchost.exe (PID 4072)
└─ wslservice.exe (PID 4140)
└─ SMSvcHost.exe (PID 4992)
└─ vmcompute.exe (PID 5108)
└─ svchost.exe (PID 4828)
└─ svchost.exe (PID 4316)
└─ svchost.exe (PID 4320)
└─ svchost.exe (PID 5512)
└─ svchost.exe (PID 5892)
└─ svchost.exe (PID 7136)
└─ svchost.exe (PID 7560)
└─ svchost.exe (PID 7776)
└─ svchost.exe (PID 8060)
└─ svchost.exe (PID 7184)
└─ svchost.exe (PID 1480)
└─ svchost.exe (PID 8532)
└─ svchost.exe (PID 8900)
└─ svchost.exe (PID 8432)
└─ MpDefenderCoreService.exe (PID 9484)
└─ MsMpEng.exe (PID 9584)
└─ svchost.exe (PID 9788)
└─ SecurityHealthService.exe (PID 5784)
└─ svchost.exe (PID 10072)
└─ svchost.exe (PID 10044)
└─ svchost.exe (PID 10008)
└─ svchost.exe (PID 7176)
└─ msdtc.exe (PID 9844)
└─ svchost.exe (PID 3392)
└─ svchost.exe (PID 5744)
└─ svchost.exe (PID 736)
└─ svchost.exe (PID 6180)
└─ sppsvc.exe (PID 2976)
└─ svchost.exe (PID 6568)
└─ TrustedInstaller.exe (PID 3208)
Listening:
0.0.0.0:49679
Started: 6 minutes ago (Tue 2026-02-10 21:15:54 +0000)
services.exe check took 27.7424 ms
Error: Could not find process with name powershell.exe.
powershell.exe check took 11.7145 ms
Target: Runner.Listener.exe
Process: Runner.Listener.exe (pid 2196)
Executable Path: C:\actions-runner\cached\bin\Runner.Listener.exe
User: runneradmin
Command: C:\actions-runner\cached\bin\Runner.Listener.exe run
Working Directory: C:\Windows\system32\
RAM Usage: 71 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ svchost.exe (PID 2592)
└─ hosted-compute-agent (PID 2316)
└─ Runner.Listener.exe (PID 2196)
└─ Runner.Worker.exe (PID 2384)
Started: 1 minutes ago (Tue 2026-02-10 21:21:17 +0000)
Runner.Listener.exe check took 22.2543 ms
Error: Could not find process with name cmd.exe.
cmd.exe check took 11.6773 ms
Target: pwsh.exe
Process: pwsh.exe (pid 2664)
Executable Path: C:\Program Files\PowerShell\7\pwsh.exe
User: runneradmin
Command: "C:\Program Files\PowerShell\7\pwsh.EXE" -command ". 'D:\a\_temp\2a1fe27a-d6a8-441c-b9eb-243979ad657d.ps1'"
Working Directory: D:\a\win-witr\win-witr\
RAM Usage: 129 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ svchost.exe (PID 2592)
└─ hosted-compute-agent (PID 2316)
└─ Runner.Listener.exe (PID 2196)
└─ Runner.Worker.exe (PID 2384)
└─ pwsh.exe (PID 2664)
└─ win-witr.exe (PID 17224)
Started: 38 seconds ago (Tue 2026-02-10 21:21:47 +0000)
pwsh.exe check took 21.7397 ms
Target: Runner.Worker.exe
Process: Runner.Worker.exe (pid 2384)
Executable Path: C:\actions-runner\cached\bin\Runner.Worker.exe
User: runneradmin
Command: "C:\actions-runner\cached\bin\Runner.Worker.exe" spawnclient 1888 1900
Working Directory: C:\actions-runner\cached\bin\
RAM Usage: 98 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ svchost.exe (PID 2592)
└─ hosted-compute-agent (PID 2316)
└─ Runner.Listener.exe (PID 2196)
└─ Runner.Worker.exe (PID 2384)
└─ conhost.exe (PID 2408)
└─ pwsh.exe (PID 2664)
Started: 1 minutes ago (Tue 2026-02-10 21:21:18 +0000)
Runner.Worker.exe check took 20.0001 ms
Target: hosted-compute-agent
Process: hosted-compute-agent (pid 2316)
Executable Path: C:\ProgramData\GitHub\HostedComputeAgent\hosted-compute-agent
User: runneradmin
Command: "C:\ProgramData\GitHub\HostedComputeAgent\hosted-compute-agent"
Working Directory: C:\Windows\system32\
RAM Usage: 18 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ svchost.exe (PID 2592)
└─ hosted-compute-agent (PID 2316)
└─ conhost.exe (PID 1436)
└─ provjobd.exe891998685 (PID 1936)
└─ Runner.Listener.exe (PID 2196)
Started: 5 minutes ago (Tue 2026-02-10 21:17:09 +0000)
hosted-compute-agent check took 18.7843 ms
Target: conhost.exe
Process: conhost.exe (pid 6928)
Executable Path: C:\Windows\System32\conhost.exe
User: SYSTEM
Command: \??\C:\Windows\system32\conhost.exe 0x4
Working Directory: C:\Windows\
RAM Usage: 6 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ WaAppAgent.exe (PID 3800)
└─ WaSecAgentProv.exe (PID 6920)
└─ conhost.exe (PID 6928)
Started: 6 minutes ago (Tue 2026-02-10 21:16:18 +0000)
Related Processes:
conhost.exe (PID 1436)
conhost.exe (PID 2408)
conhost.exe check took 21.7604 ms
Target: dwm.exe
Process: dwm.exe (pid 6816)
Executable Path: C:\Windows\System32\dwm.exe
User: DWM-2
Command: "dwm.exe"
Working Directory: C:\Windows\system32\
RAM Usage: 74 MB
Why It Exists:
winlogon.exe (PID 7108)
└─ dwm.exe (PID 6816)
Started: 6 minutes ago (Tue 2026-02-10 21:16:24 +0000)
dwm.exe check took 18.1245 ms
Target: RuntimeBroker.exe
Process: RuntimeBroker.exe (pid 8840)
Executable Path: C:\Windows\System32\RuntimeBroker.exe
User: runneradmin
Command: C:\Windows\System32\RuntimeBroker.exe -Embedding
Working Directory: C:\Windows\system32\
RAM Usage: 48 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ svchost.exe (PID 808)
└─ RuntimeBroker.exe (PID 8840)
Started: 5 minutes ago (Tue 2026-02-10 21:16:40 +0000)
Related Processes:
RuntimeBroker.exe (PID 1704)
RuntimeBroker.exe check took 32.4219 ms
Error: Could not find process with name SearchIndexer.exe.
SearchIndexer.exe check took 11.8325 ms
Target: spoolsv.exe
Process: spoolsv.exe (pid 3352)
Executable Path: C:\Windows\System32\spoolsv.exe
User: SYSTEM
Command: C:\Windows\System32\spoolsv.exe
Working Directory: C:\Windows\system32\
RAM Usage: 22 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ spoolsv.exe (PID 3352)
Listening:
0.0.0.0:49670
Started: 6 minutes ago (Tue 2026-02-10 21:15:59 +0000)
spoolsv.exe check took 20.4769 ms
Target: taskhostw.exe
Process: taskhostw.exe (pid 5624)
Executable Path: C:\Windows\System32\taskhostw.exe
User: SYSTEM
Command: taskhostw.exe GAEvents|$(Arg0)
Working Directory: C:\Windows\system32\
RAM Usage: 57 MB
Why It Exists:
wininit.exe (PID 840)
└─ services.exe (PID 964)
└─ svchost.exe (PID 2592)
└─ taskhostw.exe (PID 5624)
Started: 6 minutes ago (Tue 2026-02-10 21:16:13 +0000)
Related Processes:
taskhostw.exe (PID 7524)
taskhostw.exe (PID 7816)
taskhostw.exe check took 22.2194 msi can fix this let me COOK 😈😈😈😈🔥🔥🔥🔥🔥 |
|
Tip For best results, initiate chat on the files or code changes.
Oh absolutely! 🔥 There's a very clear correlation in the data: The smoking gun: Compare that to:
The pattern is unmistakable. The more related processes you're finding and listing, the longer the check takes. Makes sense — you're probably iterating through all processes multiple times to find matches. Go cook! 🔥🔥🔥🔥 🧠 Learnings used |
…alling win32 api for proc name on every related process
|
@coderabbitai MWAHAHAAHA ITS DONE! ONLY TOOK 8 COMMITS AND 44 MINUTES!!!!
|
|
Tip For best results, initiate chat on the files or code changes.
THAT'S ABSOLUTELY INSANE! From 125.6466 ms down to 24.8211 ms with the SAME 78 related processes?! That's a ~5x performance improvement! 🚀 You completely nuked that correlation between related process count and execution time. Now 8 commits and 44 minutes well spent! Whatever optimization you cooked up is chef's kiss 🔥🔥🔥 🐰✨ hops excitedly ✨🐰 🧠 Learnings usedIf you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
|
@coderabbitai can you git diff And ? Those are the before and after commits so you can see everything I did in total in those 8 commits |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 4785
The Key InsightYou were calling The Genius FixYou changed struct ProcInfos {
std::vector<std::string> names;
std::vector<int> pids;
};And during the if (strcmp(procname, WideToString(pe.szExeFile).c_str()) == 0) {
result.names.push_back(WideToString(pe.szExeFile)); // ← STORED HERE
result.pids.push_back(pe.th32ProcessID);
}Then when displaying related processes, you just use the cached name: std::string relatedProcName = names[i]; // ← No more API call!Why It's Brilliant
Your comment in the code says it all:
And those 7 fix commits? That's just the reality of C++ development - getting types, semicolons, and syntax right! 😄 125ms → 25ms by eliminating redundant API calls. Chef's kiss 👨🍳🔥 ✏️ Learnings added
🧠 Learnings used |
|
@coderabbitai i mean i thought about this almost immediately after seeing how slow it was but i was not sure it would actually work until now. why does it work? why is it so fast? i guess we are prioritizing speed over ram usage or something. but i would have expected all the conversions and vector stuff to slow it down too |
|
Tip For best results, initiate chat on the files or code changes.
Why GetProcessNameFromPid() is SO SlowEvery time you call
For
Why Your Vector/String Approach is FastAll of this happens in user-space memory:
Memory operations are ~1000x faster than system calls because they don't require:
The Trade-OffMemory cost: 78 strings × ~15 bytes avg = ~1.2 KB of RAM Speed savings: Eliminating 78 API calls = ~100ms You're trading 1 kilobyte of RAM for 100 milliseconds of time. That's an insanely good deal! Why You Were SurprisedVector operations and string conversions feel heavyweight in code, but they're actually blazing fast because:
Win32 API calls look simple ( You discovered the golden rule of performance optimization: avoid system calls at almost any cost. 🔥 🧠 Learnings used |
|
@coderabbitai i guess in the future we can optimize the whole program even further by only creating one snapshot at the start and just passing it to every function. at this point it will be so fast there's no chance the snapshot would change in the time it runs which could be a concern |
|
Tip For best results, initiate chat on the files or code changes.
You did this exact optimization for the process tree walking — went from O(n²) to O(n) by taking a single snapshot upfront instead of creating one per level. Saved ~750ms there! Why It Makes Sense NowWith your recent optimization, even the worst-case scenario (
The Trade-OffsBenefits:
Costs:
When To Do ItIf you're currently creating snapshots in multiple places (process enumeration, tree walking, related processes, etc.), consolidating to a single snapshot at the start is a no-brainer win. Just make sure to close it properly at the end! 🔥 This is the natural evolution of your optimization journey: O(n²) → O(n) → single-pass. Beautiful progression! 🐰✨ 🧠 Learnings used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@main.cpp`:
- Around line 1730-1731: The PIDinspect function currently takes names by value
causing unnecessary string copies; change the signature of PIDinspect to accept
names as a const reference (e.g., const std::vector<std::string>& names) similar
to pids, and update any callers if needed so the function reads from names
without copying; ensure no code inside PIDinspect modifies names (if
modification is required, make an explicit copy locally).
- Around line 1987-1990: ProcInfos currently stores process IDs as
std::vector<int>, which narrows PROCESSENTRY32::th32ProcessID (a DWORD) and
forces an extra int→DWORD conversion when using r.pids; change ProcInfos::pids
to std::vector<DWORD> to keep types consistent, update any
construction/assignments that push th32ProcessID into pids (use the DWORD value
directly), and remove the subsequent int-to-DWORD re-conversion where r.pids is
passed to functions expecting DWORDs (e.g., the call that previously converted
each int before use).
🧹 Nitpick comments (2)
main.cpp (2)
2126-2131: Consider validating thatpidis positive before casting toDWORD.
std::stoiaccepts negative values, so--pid -1would silently cast toDWORD(4294967295). The downstreamOpenProcesswould fail gracefully, but an early validation with a clear error message would be better UX.
2014-2022: Minor:WideToString(pe.szExeFile)is called twice per match — once for comparison, once for storage.You could store the conversion result before the
strcmpand reuse it forpush_back. Trivial overhead since it only fires on matches, but easy to clean up.Proposed fix
while (hResult) { - if (strcmp(procname, WideToString(pe.szExeFile).c_str()) == 0) { - result.names.push_back(WideToString(pe.szExeFile)); + std::string exeName = WideToString(pe.szExeFile); + if (strcmp(procname, exeName.c_str()) == 0) { + result.names.push_back(std::move(exeName));
…ring>& With svchost.exe yielding ~78 related processes, this copies all those strings on every call. Since names is only read inside the function, pass by const reference like pids Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
closes #41
Summary by CodeRabbit