Commit 6783347
perf(ext/node): skip node:http perf timing without observers (#34409)
## Summary
Avoids unconditional `performance.now()` work on the node:http server
request hot path when there are no Node `PerformanceObserver`s
interested in `entryType: "http"`.
The previous implementation timestamped every incoming server request,
then discovered at finish time whether any observer wanted an
`HttpRequest` entry. This patch mirrors Node's shape more closely: Node
gates `startPerf()` in `lib/_http_server.js` behind
`hasObserver('http')`, and gates `_finish()` behind both stored perf
state and `hasObserver('http')`.
## Node compatibility
Checked upstream Node main:
- `lib/_http_server.js`: `ServerResponse` calls `startPerf(...)` only
when `hasObserver('http')` is true.
- `lib/_http_server.js`: `_finish()` calls `stopPerf(...)` only when
response perf state exists and `hasObserver('http')` is still true.
- `lib/internal/perf/observe.js`: `hasObserver(type)` reads the internal
observer count for the entry type.
Behavior spot-checks against Node v25.9.0:
- Observer attached before a request sees an `HttpRequest` entry with
request and response detail.
- Observer attached after request start but before response finish does
not receive a retroactive server entry.
- Observer disconnected before response finish does not receive the
entry.
## Validation
Correctness:
```sh
DENO_TEST_UTIL_DENO_EXE=/home/bot/work/stuff/shared/a3f6b36b-f67/workers/313cb9ff-3b9/perf-http-observer-validation-20260527T014052Z/deno-candidate cargo test -p unit_node_tests --test unit_node -- perf_hooks_test
```
Result: passed, 1 file-test (`tests/unit_node/perf_hooks_test.ts`).
Benchmark command, execution target `bigboi`:
```sh
RUN_DIR=/home/bot/work/stuff/shared/a3f6b36b-f67/workers/c68aca61-79c/perf-http-observer-rerun-20260527T055454Z \
BASELINE=/home/bot/work/stuff/shared/a3f6b36b-f67/workers/313cb9ff-3b9/perf-http-observer-validation-20260527T014052Z/deno-baseline \
CANDIDATE=/home/bot/work/stuff/shared/a3f6b36b-f67/workers/313cb9ff-3b9/perf-http-observer-validation-20260527T014052Z/deno-candidate \
SERVER=$RUN_DIR/server_get.mjs \
SAMPLES=8 DURATION=8s WARMUP=3s CONNECTIONS=128 SERVER_CPU=2 CLIENT_CPUS=3-5 \
$RUN_DIR/run_get_bench.sh
```
Fresh 8-sample rerun:
- Baseline: 10,987.68 req/s mean, median 10,813.26, CV 7.72%.
- Candidate: 11,482.77 req/s mean, median 11,406.40, CV 8.38%.
- Paired delta: +495.10 req/s, +5.04% mean; 6/8 pairs positive.
- Confidence: directional improvement, but noisy; the 95% interval on
percent delta crosses zero.
Earlier same-target 20-sample validation using the same release-lite
binaries:
- Baseline: 14,909.34 req/s mean, CV 10.54%.
- Candidate: 15,419.35 req/s mean, CV 6.21%.
- Paired delta: +510.01 req/s, +4.07% mean; 13/20 pairs positive.
- 95% CI: delta req/s [-65.93, 1085.96], percent delta [0.22%, 7.92%].
- Confidence: moderate; noisy host, but the larger paired run supports a
small real improvement.
Co-authored-by: Nathan Whitaker <nathan@deno.com>1 parent 2e016f4 commit 6783347
3 files changed
Lines changed: 105 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
93 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| |||
824 | 825 | | |
825 | 826 | | |
826 | 827 | | |
827 | | - | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
828 | 831 | | |
829 | 832 | | |
830 | 833 | | |
| |||
1009 | 1012 | | |
1010 | 1013 | | |
1011 | 1014 | | |
1012 | | - | |
| 1015 | + | |
1013 | 1016 | | |
1014 | 1017 | | |
1015 | 1018 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
163 | 172 | | |
164 | 173 | | |
165 | 174 | | |
| |||
609 | 618 | | |
610 | 619 | | |
611 | 620 | | |
| 621 | + | |
612 | 622 | | |
613 | 623 | | |
614 | 624 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
0 commit comments