[PR #3789] [Other] procs.py: Windows engine start 5.6 s sooner by improving orphan search (6.2 -> 0.1 s) #4783

Open
opened 2026-11-07 15:39:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3789
Author: @page1
Created: 10/23/2026
Status: 🔄 Open

Base: main ← Head: fix/orphan-scan-windows


📝 Commits (1)

  • 0a11fbd serve (Windows): the orphan search before an engine start lists processes by command line only (6.2 s -> 0.1 s)

📊 Changes

1 file changed (+9 additions, -3 deletions)

View changed files

📝 strata_control/procs.py (+9 -3)

📄 Description

Problem and result

Before every engine start, the server looks for engines that an earlier run left behind
(strata_control/procs.py, orphans_of). The search asks psutil for every process's parent and start time while
listing processes. On Windows, psutil reads a process's parent from a snapshot of the whole system, once per process,
and falls back to another whole-system snapshot for the start time of every process where OpenProcess is denied
(system and other accounts' processes). With 474 processes running (207 of them access-denied), the search took
6.1-6.5 s; with more programs open, 8.4-8.9 s. The server is a fresh process at every
start, so nothing is cached, and the engine waits that long before it is launched.

After the change the search takes 0.10 s, and the engine is launched 5.6 s sooner.

A focused fix, no issue; it came up while timing engine starts for #2672. #3254 (open) also changes
strata_control/procs.py: which ancestors count as starters, and how end_one() waits. This PR changes only how
the processes are listed, and the two merge without conflicts (git merge-tree of both heads).

Approach

  • The process list carries only the command line (0.01 s for 474 processes).
  • A process's parent and start time are read only when it runs --serve from this executable: normally none, at
    most the orphan itself.
  • What counts as an orphan is unchanged: the same checks, in the same order, on the same processes. A parent that
    can't be read counts as unknown, as before (process_iter gave None for it). One difference: a candidate whose
    start time can't be read is now skipped; in 0.2.2 it gave None + 1.0, a TypeError that ended the whole search.
  • On Linux the parent and start time come from /proc and were already cheap; there the change only stops reading
    them for processes that aren't candidates.

Validation

Passed: (at 0a11fbd9, which is 0.2.2 011c9e60 plus this commit)

On Windows 11 26300 (Python 3.13, psutil 7.2.2, 474 processes running), RTX 3090, Core Ultra 9 285K, IQ3_S at 262K,
with the same 0.2.2 engine before and after:

Measure 0.2.2 This PR n
procs.end_orphans() (the function the server calls before each start), in a fresh Python process 6.11 / 6.19 / 6.47 s 0.10 / 0.10 / 0.11 s 3 + 3
server start to strata.exe created 6.91 s 1.26 s 1 + 1
server start to loaded 22.78 s 17.34 s 1 + 1

The two server-start rows are one start each way (every server and engine line and every new child process
timestamped every 50 ms), so the 5.6 s in the title has n = 1; the search time it removes is the 3 + 3 row. This is
one of a series of Windows start-time changes: the engine-side ones in #2672 were measured more thoroughly there
(8 + 8 + 8 and 10 + 10 engine starts, and 3 + 3 server starts together with this fix).

Command for the first row, from the repo root:

python -c "import time; from strata_control import procs; t=time.time(); procs.end_orphans(r'<path to strata.exe>'); print(time.time()-t)"
  • python -m unittest tests.terminal.test_procs: 7/7. Its orphan test starts a real orphan and checks that it is
    found and ended, and that a process with a live parent is not.
  • python -m unittest tests.terminal.test_cloudflared_find tests.terminal.test_file_in_use tests.terminal.test_models_move serve.test_lifeline: the same results as on 0.2.2 (49 tests, 8 skipped either
    way).

Failed: none observed.

Not run: Linux and macOS. The changed function runs there too, with fewer lookups; I have no Linux or Mac
machine to run the tests on. If anyone on Linux or macOS can run python -m unittest tests.terminal.test_procs on
this branch, I'd appreciate the confirmation.

Limits

The time saved grows with the number of processes running: a PC with a browser and many apps open saves more.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3789 **Author:** [@page1](https://github.com/page1) **Created:** 10/23/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/orphan-scan-windows` --- ### 📝 Commits (1) - [`0a11fbd`](https://github.com/Niko1221/Strata/commit/0a11fbd9bf905544554dadc6624f3649d34bfcdb) serve (Windows): the orphan search before an engine start lists processes by command line only (6.2 s -> 0.1 s) ### 📊 Changes **1 file changed** (+9 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `strata_control/procs.py` (+9 -3) </details> ### 📄 Description ## Problem and result Before every engine start, the server looks for engines that an earlier run left behind (`strata_control/procs.py`, `orphans_of`). The search asks psutil for every process's parent and start time while listing processes. On Windows, psutil reads a process's parent from a snapshot of the whole system, once per process, and falls back to another whole-system snapshot for the start time of every process where `OpenProcess` is denied (system and other accounts' processes). With 474 processes running (207 of them access-denied), the search took 6.1-6.5 s; with more programs open, 8.4-8.9 s. The server is a fresh process at every start, so nothing is cached, and the engine waits that long before it is launched. After the change the search takes 0.10 s, and the engine is launched 5.6 s sooner. ## Related discussion A focused fix, no issue; it came up while timing engine starts for #2672. #3254 (open) also changes `strata_control/procs.py`: which ancestors count as starters, and how `end_one()` waits. This PR changes only how the processes are listed, and the two merge without conflicts (`git merge-tree` of both heads). ## Approach - The process list carries only the command line (0.01 s for 474 processes). - A process's parent and start time are read only when it runs `--serve` from this executable: normally none, at most the orphan itself. - What counts as an orphan is unchanged: the same checks, in the same order, on the same processes. A parent that can't be read counts as unknown, as before (`process_iter` gave `None` for it). One difference: a candidate whose start time can't be read is now skipped; in 0.2.2 it gave `None + 1.0`, a `TypeError` that ended the whole search. - On Linux the parent and start time come from `/proc` and were already cheap; there the change only stops reading them for processes that aren't candidates. ## Validation **Passed:** (at 0a11fbd9, which is 0.2.2 `011c9e60` plus this commit) On Windows 11 26300 (Python 3.13, psutil 7.2.2, 474 processes running), RTX 3090, Core Ultra 9 285K, IQ3_S at 262K, with the same 0.2.2 engine before and after: | Measure | 0.2.2 | This PR | n | |---|---|---|---| | `procs.end_orphans()` (the function the server calls before each start), in a fresh Python process | 6.11 / 6.19 / 6.47 s | 0.10 / 0.10 / 0.11 s | 3 + 3 | | server start to `strata.exe` created | 6.91 s | 1.26 s | 1 + 1 | | server start to loaded | 22.78 s | 17.34 s | 1 + 1 | The two server-start rows are one start each way (every server and engine line and every new child process timestamped every 50 ms), so the 5.6 s in the title has n = 1; the search time it removes is the 3 + 3 row. This is one of a series of Windows start-time changes: the engine-side ones in #2672 were measured more thoroughly there (8 + 8 + 8 and 10 + 10 engine starts, and 3 + 3 server starts together with this fix). Command for the first row, from the repo root: python -c "import time; from strata_control import procs; t=time.time(); procs.end_orphans(r'<path to strata.exe>'); print(time.time()-t)" - `python -m unittest tests.terminal.test_procs`: 7/7. Its orphan test starts a real orphan and checks that it is found and ended, and that a process with a live parent is not. - `python -m unittest tests.terminal.test_cloudflared_find tests.terminal.test_file_in_use tests.terminal.test_models_move serve.test_lifeline`: the same results as on 0.2.2 (49 tests, 8 skipped either way). **Failed:** none observed. **Not run:** Linux and macOS. The changed function runs there too, with fewer lookups; I have no Linux or Mac machine to run the tests on. If anyone on Linux or macOS can run `python -m unittest tests.terminal.test_procs` on this branch, I'd appreciate the confirmation. ## Limits The time saved grows with the number of processes running: a PC with a browser and many apps open saves more. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4783
No description provided.