Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: small perf improvements #2661

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,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))
KhafraDev marked this conversation as resolved.
Show resolved Hide resolved
? performance.markResourceTiming
: () => {}

// https://fetch.spec.whatwg.org/#abort-fetch
function abortFetch (p, request, responseObject, error) {
Expand Down Expand Up @@ -1044,7 +1042,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we detect if somebody is listening to these resourceTiminig? This seems like an expensive call that we could potentially skip if there is no one watching.

}
}

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
Loading