From e090574effa60942eb0262966eae94f6ce300c27 Mon Sep 17 00:00:00 2001 From: Spinnich Date: Mon, 7 Sep 2026 17:25:47 +0000 Subject: [PATCH 1/3] perf(scan): default to 4 scan workers instead of 1 Hashing 1.96 GiB of real ROM files is 2.2x faster at 4 concurrent workers than at 1 (108 -> 240 MiB/s on 16 cores, 108 -> 264 MiB/s pinned to 4 cores). Pinned to 2 cores it is still 1.6x, so the new default costs nothing on small hosts. Metadata providers cap themselves independently of this value, so the extra workers queue rather than exceed an allowance: ScreenScraper holds a concurrency limiter set to the account's advertised thread count, and the other adapters pace their own request rate. Database work in the scan path is synchronous on the event loop, so it serializes regardless and the connection pool is unaffected. The compose example advised one worker per CPU, which overshoots on a large host. Both it and env.template now say what raising this actually buys, since metadata is paced no matter how many workers there are. Only installs that never set SCAN_WORKERS move; any explicit value is preserved. Co-Authored-By: Claude Opus 5 --- backend/config/__init__.py | 2 +- docs/BACKEND_ARCHITECTURE.md | 2 +- env.template | 2 +- examples/docker-compose.example.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/config/__init__.py b/backend/config/__init__.py index 4f21a38b4..56916cf6f 100644 --- a/backend/config/__init__.py +++ b/backend/config/__init__.py @@ -229,7 +229,7 @@ OIDC_END_SESSION_ENDPOINT: Final[str] = _get_env("OIDC_END_SESSION_ENDPOINT", "" # SCANS SCAN_TIMEOUT: Final[int] = safe_int(_get_env("SCAN_TIMEOUT"), 60 * 60 * 4) # 4 hours -SCAN_WORKERS: Final[int] = max(1, safe_int(_get_env("SCAN_WORKERS"), 1)) +SCAN_WORKERS: Final[int] = max(1, safe_int(_get_env("SCAN_WORKERS"), 4)) # TASKS TASK_TIMEOUT: Final[int] = safe_int(_get_env("TASK_TIMEOUT"), 60 * 5) # 5 minutes diff --git a/docs/BACKEND_ARCHITECTURE.md b/docs/BACKEND_ARCHITECTURE.md index 7b3eaae25..9b2290cb0 100644 --- a/docs/BACKEND_ARCHITECTURE.md +++ b/docs/BACKEND_ARCHITECTURE.md @@ -1627,7 +1627,7 @@ Falls back to `FakeRedis` in test mode. | Variable | Default | Description | | -------------------------------------- | ----------- | ------------------------------- | | `SCAN_TIMEOUT` | `14400` | 4-hour scan timeout | -| `SCAN_WORKERS` | `1` | Concurrent scan workers | +| `SCAN_WORKERS` | `4` | Concurrent scan workers | | `TASK_TIMEOUT` | | RQ job timeout for manual tasks | | `TASK_RESULT_TTL` | | How long to keep job results | | `ENABLE_SCHEDULED_RESCAN` | `false` | Auto library rescan | diff --git a/env.template b/env.template index 3c9609a18..4dd735f06 100644 --- a/env.template +++ b/env.template @@ -84,7 +84,7 @@ TGDB_API_ENABLED=false # Enable TheGamesDB API integration # Scans & Tasks SCAN_TIMEOUT=14400 # Timeout for background scan/rescan tasks in seconds -SCAN_WORKERS=1 # How many ROMs a scan processes at once +SCAN_WORKERS=4 # How many ROMs a scan processes at once; mainly speeds up hashing, as metadata providers pace themselves TASK_TIMEOUT=300 # Timeout for other background tasks in seconds TASK_RESULT_TTL=86400 # How long to keep task results in Valkey in seconds SEVEN_ZIP_TIMEOUT=60 # Timeout for 7-Zip operations in seconds diff --git a/examples/docker-compose.example.yml b/examples/docker-compose.example.yml index 67f20f40a..0b25c8231 100644 --- a/examples/docker-compose.example.yml +++ b/examples/docker-compose.example.yml @@ -19,7 +19,7 @@ services: - RETROACHIEVEMENTS_API_KEY= # https://docs.romm.app/latest/Getting-Started/Metadata-Providers/#retroachievements - STEAMGRIDDB_API_KEY= # https://docs.romm.app/latest/Getting-Started/Metadata-Providers/#steamgriddb - HASHEOUS_API_ENABLED=true # https://docs.romm.app/latest/Getting-Started/Metadata-Providers/#hasheous - - SCAN_WORKERS=2 # How many items you want scanned at once, we recommend 1 worker per CPU. + - SCAN_WORKERS=4 # How many ROMs to scan at once; mainly speeds up hashing, as metadata providers pace themselves - WEB_SERVER_CONCURRENCY=3 # How many workers you want available for API calls and tasks we recommend 2 x CPU + 1 volumes: - romm_resources:/romm/resources # Resources fetched from IGDB (covers, screenshots, etc.) From 7365d177380eef63a114483594e5a7a78d318326 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 7 Sep 2026 14:15:25 -0400 Subject: [PATCH 2/3] cleanup --- env.template | 2 +- examples/docker-compose.example.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/env.template b/env.template index 4dd735f06..7bf98b3fb 100644 --- a/env.template +++ b/env.template @@ -84,7 +84,7 @@ TGDB_API_ENABLED=false # Enable TheGamesDB API integration # Scans & Tasks SCAN_TIMEOUT=14400 # Timeout for background scan/rescan tasks in seconds -SCAN_WORKERS=4 # How many ROMs a scan processes at once; mainly speeds up hashing, as metadata providers pace themselves +SCAN_WORKERS=4 # How many ROMs a scan processes at once TASK_TIMEOUT=300 # Timeout for other background tasks in seconds TASK_RESULT_TTL=86400 # How long to keep task results in Valkey in seconds SEVEN_ZIP_TIMEOUT=60 # Timeout for 7-Zip operations in seconds diff --git a/examples/docker-compose.example.yml b/examples/docker-compose.example.yml index 0b25c8231..7427b7a8f 100644 --- a/examples/docker-compose.example.yml +++ b/examples/docker-compose.example.yml @@ -19,7 +19,7 @@ services: - RETROACHIEVEMENTS_API_KEY= # https://docs.romm.app/latest/Getting-Started/Metadata-Providers/#retroachievements - STEAMGRIDDB_API_KEY= # https://docs.romm.app/latest/Getting-Started/Metadata-Providers/#steamgriddb - HASHEOUS_API_ENABLED=true # https://docs.romm.app/latest/Getting-Started/Metadata-Providers/#hasheous - - SCAN_WORKERS=4 # How many ROMs to scan at once; mainly speeds up hashing, as metadata providers pace themselves + - SCAN_WORKERS=4 # How many ROMs to scan at once - WEB_SERVER_CONCURRENCY=3 # How many workers you want available for API calls and tasks we recommend 2 x CPU + 1 volumes: - romm_resources:/romm/resources # Resources fetched from IGDB (covers, screenshots, etc.) From 1067222ecd1807f4adb9dd483a10d772c0f15a16 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 7 Sep 2026 14:24:38 -0400 Subject: [PATCH 3/3] update polish skill --- .claude/skills/review-polish/SKILL.md | 51 ++++----------------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/.claude/skills/review-polish/SKILL.md b/.claude/skills/review-polish/SKILL.md index 4bf6cd302..18da72963 100644 --- a/.claude/skills/review-polish/SKILL.md +++ b/.claude/skills/review-polish/SKILL.md @@ -7,11 +7,11 @@ description: The before-review and before-handoff pass for RomM, covering both s Two passes, in order, once the change works: -1. **Polish (A–F):** shape the code the checks can't see. Derived from the +1. **Polish (A–D):** shape the code the checks can't see. Derived from the corrections a maintainer actually pushed on top of 37 approved contributor PRs — every rule below is something that got hand-fixed after review, so applying it up front saves a round trip. -2. **Verify (G):** run the checks that match what you touched, mirroring the CI +2. **Verify (E):** run the checks that match what you touched, mirroring the CI gates so review isn't the first place a failure shows up. Polish comes first, since it renames things, extracts helpers, and edits tests; `trunk fmt && trunk check` comes last of all, so nothing lands unformatted. If @@ -94,25 +94,7 @@ trimmed too. --- -## C. Reuse the existing mechanism before inventing one - -- **Use the existing foreign key.** A durable-reference scheme of your own - (`(rom_id, md5_hash)` because file ids churn on rescan) loses to - `rom_file_id` with `ondelete="CASCADE"`. If the real problem is churn, fix the - churn. -- **Reach for VueUse before hand-rolling.** Persisted UI state is - `useLocalStorage(key, default, { writeDefaults: false, serializer })`, not a - `ref` plus a `watch` plus `localStorage.setItem`. -- **Put display logic on the component that renders it.** A bespoke - `ratingChips` computed in a tab belongs in the card component and its - `providers.ts` config. -- **Prefer a spread over mutate-after-construct.** - `{ ...(x !== undefined ? { x } : {}) }` over building an object then - conditionally assigning. - ---- - -## D. Names say what the thing does +## C. Names say what the thing does - `syncRom` renamed to `syncCachedRom`: it updates the cache, it does not fetch. - Sort on `display_name` when `display_name` is what the user sees. @@ -122,7 +104,7 @@ short a word. --- -## E. Tests: strict typing is part of the test +## D. Tests: strict typing is part of the test Trunk runs mypy over `backend/tests/`, and `vue-tsc` covers frontend tests. Both catch these, but only after the contributor has handed the PR over. @@ -142,25 +124,7 @@ catch these, but only after the contributor has handed the PR over. --- -## F. Async and reactive lifecycle (v2) - -See `frontend-v2-patterns` for the full set. The three that get fixed in review: - -1. **Snapshot any reactive value a decision depends on before the first - `await`.** The selection and the collection's `rom_ids` both move while - requests are in flight, so `const wasAllFavorited = allFavorited.value` comes - before the call, not after. -2. **Watch the narrowest source.** Watching `authStore.user` refires on every - unrelated profile update; watch a derived primitive - (`user?.oauth_scopes.includes("tasks.run") ? user.id : null`) so the - watch is self-guarding and no manual "already ran for this id" flag is - needed. -3. **Guard late resolutions with `useIsAlive()`** rather than a local - `unmounted` flag and `onBeforeUnmount`. - ---- - -## G. Verification before handoff +## E. Verification before handoff Run the checks that match what you touched. **Static checks don't prove a feature works** — when UI changed, also test it in the browser. **Never @@ -232,12 +196,9 @@ Run from `backend/`: - [ ] No comment or docstring over two lines of prose; no change history, no restatement, no justification of the obvious - [ ] Every new constant, type, limit, and getter searched for first -- [ ] No new mechanism where an FK, a VueUse composable, or an existing - component already does it - [ ] Names say what the code touches - [ ] Tests typecheck strictly and exercise the production path -- [ ] Reactive values snapshotted before `await`; watches on narrow sources -- [ ] Stack checks in G green for everything touched (typecheck/test/build, +- [ ] Stack checks in E green for everything touched (typecheck/test/build, pytest, migrations both directions, OpenAPI regen) - [ ] UI changes tested in the browser: both themes, all four input modalities, responsive sweep