Skip to content

Commit 4bedb9d

Browse files
Uzlopakcrysmags
authored andcommitted
chore: small perf improvements (nodejs#2661)
1 parent 88a3233 commit 4bedb9d

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

lib/fetch/index.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,17 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
303303
// global, and cacheState.
304304
markResourceTiming(
305305
timingInfo,
306-
originalURL,
306+
originalURL.href,
307307
initiatorType,
308308
globalThis,
309309
cacheState
310310
)
311311
}
312312

313313
// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
314-
function markResourceTiming (timingInfo, originalURL, initiatorType, globalThis, cacheState) {
315-
if (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2)) {
316-
performance.markResourceTiming(timingInfo, originalURL.href, initiatorType, globalThis, cacheState)
317-
}
318-
}
314+
const markResourceTiming = (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2))
315+
? performance.markResourceTiming
316+
: () => {}
319317

320318
// https://fetch.spec.whatwg.org/#abort-fetch
321319
function abortFetch (p, request, responseObject, error) {
@@ -1042,7 +1040,7 @@ function fetchFinale (fetchParams, response) {
10421040
// and responseStatus.
10431041
if (fetchParams.request.initiatorType != null) {
10441042
// TODO: update markresourcetiming
1045-
markResourceTiming(timingInfo, fetchParams.request.url, fetchParams.request.initiatorType, globalThis, cacheState, bodyInfo, responseStatus)
1043+
markResourceTiming(timingInfo, fetchParams.request.url.href, fetchParams.request.initiatorType, globalThis, cacheState, bodyInfo, responseStatus)
10461044
}
10471045
}
10481046

lib/pool.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,17 @@ class Pool extends PoolBase {
7676
}
7777

7878
[kGetDispatcher] () {
79-
let dispatcher = this[kClients].find(dispatcher => !dispatcher[kNeedDrain])
80-
81-
if (dispatcher) {
82-
return dispatcher
79+
for (const client of this[kClients]) {
80+
if (!client[kNeedDrain]) {
81+
return client
82+
}
8383
}
8484

8585
if (!this[kConnections] || this[kClients].length < this[kConnections]) {
86-
dispatcher = this[kFactory](this[kUrl], this[kOptions])
86+
const dispatcher = this[kFactory](this[kUrl], this[kOptions])
8787
this[kAddClient](dispatcher)
88+
return dispatcher
8889
}
89-
90-
return dispatcher
9190
}
9291
}
9392

0 commit comments

Comments
 (0)