Commit e30df23
authored
perf: add persistent playwright executor daemon (#113)
## Summary
Replace per-request `tsx` subprocess spawning with a persistent Node.js
daemon that maintains a warm CDP connection to the browser.
**Performance improvement: ~94% faster for simple operations**
- Before: ~750ms per request (tsx startup + module load + CDP connect)
- After: ~45ms per request (reuses daemon + warm CDP connection)
### Changes
- Add `playwright-daemon.ts`: persistent daemon that listens on Unix
socket, maintains warm CDP connection, uses esbuild for fast TypeScript
transformation
- Update `playwright.go`: communicate with daemon via Unix socket
instead of spawning tsx subprocess; lazy-start daemon on first request
- Update Dockerfiles: install esbuild, pre-compile daemon to JavaScript
during build
### Architecture
```
HTTP Request → Go API → Unix Socket → Playwright Daemon → CDP → Chromium
↑
(persistent, warm connection)
```
## Test plan
- [x] Build headless Docker image
- [x] Run performance benchmarks comparing before/after
- [x] Test TypeScript syntax support (type annotations, interfaces,
async/await)
- [x] Verify existing Go tests pass
- [ ] Manual testing in production environment
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Introduces a persistent Playwright execution daemon and switches the
API to use it over a Unix socket, removing per-request tsx subprocesses.
>
> - **New daemon**: Adds `server/runtime/playwright-daemon.ts` (compiled
to `/usr/local/lib/playwright-daemon.js`) that listens on
`/tmp/playwright-daemon.sock`, keeps a warm CDP connection, transforms
TS via `esbuild`, and reconnects on browser restarts.
> - **API changes**: `api/playwright.go` now lazy-starts the daemon,
communicates via Unix socket with request/response JSON, and returns
structured errors; `ApiService` gains fields for daemon process control.
> - **Dockerfiles**: Install `esbuild`, remove `tsx` from globals, and
compile+embed the daemon in both headful/headless images; update neko
base image reference.
> - **Tests**: Move Playwright execute test into
`e2e_playwright_test.go` and add a recovery test that restarts Chromium
and verifies daemon reconnection.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b4be529. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 046ef0b commit e30df23
File tree
8 files changed
+612
-232
lines changed- images
- chromium-headful
- chromium-headless/image
- server
- cmd/api/api
- e2e
- runtime
8 files changed
+612
-232
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
279 | | - | |
280 | | - | |
| 279 | + | |
| 280 | + | |
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | | - | |
307 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
308 | 318 | | |
309 | 319 | | |
310 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
183 | | - | |
| 182 | + | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
206 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
207 | 217 | | |
208 | 218 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
16 | 133 | | |
17 | | - | |
18 | 134 | | |
19 | 135 | | |
20 | 136 | | |
21 | 137 | | |
22 | 138 | | |
23 | | - | |
24 | 139 | | |
25 | 140 | | |
26 | 141 | | |
| |||
29 | 144 | | |
30 | 145 | | |
31 | 146 | | |
32 | | - | |
33 | 147 | | |
34 | 148 | | |
35 | 149 | | |
36 | 150 | | |
37 | 151 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 152 | + | |
| 153 | + | |
42 | 154 | | |
43 | 155 | | |
44 | | - | |
| 156 | + | |
45 | 157 | | |
46 | 158 | | |
47 | 159 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | 160 | | |
| 161 | + | |
72 | 162 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | 163 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | 164 | | |
106 | | - | |
107 | 165 | | |
108 | | - | |
| 166 | + | |
109 | 167 | | |
110 | | - | |
111 | 168 | | |
112 | 169 | | |
113 | 170 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
124 | 174 | | |
125 | | - | |
| 175 | + | |
126 | 176 | | |
127 | | - | |
| 177 | + | |
128 | 178 | | |
129 | 179 | | |
130 | 180 | | |
131 | 181 | | |
132 | | - | |
133 | | - | |
| 182 | + | |
| 183 | + | |
134 | 184 | | |
135 | 185 | | |
0 commit comments