Skip to content

Commit 04338be

Browse files
authored
Perf/startup performance (#23)
* perf: service startup performance * versioning, changelogs * adjusted versions and changelogs
1 parent ff97e5a commit 04338be

3 files changed

Lines changed: 79 additions & 11 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!-- version-type: patch -->
2+
# service
3+
4+
<!--
5+
FORMATTING GUIDE:
6+
7+
### Detailed Entry (appears first when merging)
8+
9+
Use h3 (###) and below for detailed entries with paragraphs, code examples, and lists.
10+
11+
### Simple List Items
12+
13+
- Simple changes can be added as list items
14+
- They are collected together at the bottom of each section
15+
16+
TIP: When multiple changelog drafts are merged, heading-based entries
17+
appear before simple list items within each section.
18+
-->
19+
20+
## ✨ Features
21+
<!-- PLACEHOLDER: Describe your shiny new features (feat:) -->
22+
23+
## 🐛 Bug Fixes
24+
<!-- PLACEHOLDER: Describe the nasty little bugs that has been eradicated (fix:) -->
25+
26+
## 📚 Documentation
27+
<!-- PLACEHOLDER: Describe documentation changes (docs:) -->
28+
29+
## ⚡ Performance
30+
- Improved service startup performance with parallel REST API initialization and deferred stale process detection
31+
32+
## ♻️ Refactoring
33+
<!-- PLACEHOLDER: Describe code refactoring (refactor:) -->
34+
35+
## 🧪 Tests
36+
<!-- PLACEHOLDER: Describe test changes (test:) -->
37+
38+
## 📦 Build
39+
<!-- PLACEHOLDER: Describe build system changes (build:) -->
40+
41+
## 👷 CI
42+
<!-- PLACEHOLDER: Describe CI configuration changes (ci:) -->
43+
44+
## ⬆️ Dependencies
45+
<!-- PLACEHOLDER: Describe dependency updates (deps:) -->
46+
47+
## 🔧 Chores
48+
<!-- PLACEHOLDER: Describe other changes (chore:) -->

.yarn/versions/38497d1d.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
releases:
2+
service: patch
3+
4+
declined:
5+
- stack-craft

service/src/service.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,43 @@ import { encryptExistingSecrets } from './utils/encrypt-existing-secrets.js'
2929
const host = getHost()
3030
const port = getPort()
3131

32+
const logStartupError = (scope: string, error: unknown): void => {
33+
getLogger(injector)
34+
.withScope(scope)
35+
.error({
36+
message: `Background startup task failed: ${error instanceof Error ? error.message : String(error)}`,
37+
data: { error },
38+
})
39+
.catch(() => console.error(`Background startup task failed (logger unavailable) [${scope}]`, error))
40+
}
41+
3242
const setupRestApis = async () => {
3343
await setupDataStore(injector)
3444
await setupLogStore(injector)
3545
await setupPatcher(injector)
3646

3747
injector.get(ExternalGitChangeListener).start()
3848

49+
// Stale-state cleanup and secret re-encryption don't gate REST availability — run them
50+
// in the background so HTTP can start accepting requests sooner.
3951
const processManager = injector.get(ProcessManager)
40-
await processManager.reconcileStaleStates()
52+
void processManager.reconcileStaleStates().catch((error) => logStartupError('StaleStateReconciler', error))
4153

42-
await usingAsync(useSystemIdentityContext({ injector }), async (elevated) => {
54+
void usingAsync(useSystemIdentityContext({ injector }), async (elevated) => {
4355
await encryptExistingSecrets(elevated)
44-
})
56+
}).catch((error) => logStartupError('EncryptExistingSecrets', error))
4557

46-
await setupInstallRestApi(injector)
47-
await setupIdentityRestApi(injector)
48-
await setupStacksRestApi(injector)
49-
await setupServicesRestApi(injector)
50-
await setupGitHubReposRestApi(injector)
51-
await setupPrerequisitesRestApi(injector)
52-
await setupTokensRestApi(injector)
53-
await setupSystemRestApi(injector)
58+
// Each module registers its own route group independently, so they can be set up concurrently.
59+
await Promise.all([
60+
setupInstallRestApi(injector),
61+
setupIdentityRestApi(injector),
62+
setupStacksRestApi(injector),
63+
setupServicesRestApi(injector),
64+
setupGitHubReposRestApi(injector),
65+
setupPrerequisitesRestApi(injector),
66+
setupTokensRestApi(injector),
67+
setupSystemRestApi(injector),
68+
])
5469

5570
const wsService = injector.get(WebsocketService)
5671
await wsService.init(injector)

0 commit comments

Comments
 (0)