Skip to content

Commit

Permalink
chore: small perf improvements (nodejs#2661)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored and crysmags committed Feb 27, 2024
1 parent 88a3233 commit 4bedb9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
12 changes: 5 additions & 7 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,17 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
// global, and cacheState.
markResourceTiming(
timingInfo,
originalURL,
originalURL.href,
initiatorType,
globalThis,
cacheState
)
}

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

// https://fetch.spec.whatwg.org/#abort-fetch
function abortFetch (p, request, responseObject, error) {
Expand Down Expand Up @@ -1042,7 +1040,7 @@ function fetchFinale (fetchParams, response) {
// and responseStatus.
if (fetchParams.request.initiatorType != null) {
// TODO: update markresourcetiming
markResourceTiming(timingInfo, fetchParams.request.url, fetchParams.request.initiatorType, globalThis, cacheState, bodyInfo, responseStatus)
markResourceTiming(timingInfo, fetchParams.request.url.href, fetchParams.request.initiatorType, globalThis, cacheState, bodyInfo, responseStatus)
}
}

Expand Down
13 changes: 6 additions & 7 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,17 @@ class Pool extends PoolBase {
}

[kGetDispatcher] () {
let dispatcher = this[kClients].find(dispatcher => !dispatcher[kNeedDrain])

if (dispatcher) {
return dispatcher
for (const client of this[kClients]) {
if (!client[kNeedDrain]) {
return client
}
}

if (!this[kConnections] || this[kClients].length < this[kConnections]) {
dispatcher = this[kFactory](this[kUrl], this[kOptions])
const dispatcher = this[kFactory](this[kUrl], this[kOptions])
this[kAddClient](dispatcher)
return dispatcher
}

return dispatcher
}
}

Expand Down

0 comments on commit 4bedb9d

Please sign in to comment.