Skip to content

perf: parallelize jsDelivr README fallback probes#2384

Open
trivikr wants to merge 4 commits intonpmx-dev:mainfrom
trivikr:fetch-readme-parallel
Open

perf: parallelize jsDelivr README fallback probes#2384
trivikr wants to merge 4 commits intonpmx-dev:mainfrom
trivikr:fetch-readme-parallel

Conversation

@trivikr
Copy link
Copy Markdown
Contributor

@trivikr trivikr commented Apr 5, 2026

🔗 Linked issue

N/A

🧭 Context

README fallback probing in server/utils/readme-loaders.ts was strictly sequential. On cache misses, packages with missing or nonstandard README filenames could pay for several failed jsDelivr requests before the loader found the right file or gave up, which made worst-case README render time noticeably slower than necessary.

📚 Description

This changes the jsDelivr README fallback path to reduce that long-tail latency while keeping the fallback behavior conservative.

  • Build a prioritized candidate list that tries the npm registry’s readmeFilename first when it exists.
  • Probe jsDelivr candidates in small parallel batches instead of one-by-one.
  • Preserve existing fallback semantics for missing, nonstandard, and truncated npm READMEs.
  • Add unit coverage for batched probing and candidate prioritization in test/unit/server/utils/readme-loaders.spec.ts.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Apr 5, 2026 6:58am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Apr 5, 2026 6:58am
npmx-lunaria Ignored Ignored Apr 5, 2026 6:58am

Request Review

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 615c8cb6-080b-4aae-a57b-a3330bf18b20

📥 Commits

Reviewing files that changed from the base of the PR and between 72bb0b2 and 9048f42.

📒 Files selected for processing (1)
  • server/utils/readme-loaders.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/utils/readme-loaders.ts

📝 Walkthrough

Walkthrough

The PR changes README fetching in server/utils/readme-loaders.ts to fetch candidate filenames in batches of three concurrently via Promise.all. fetchReadmeFromJsdelivr now returns the first successful body found per batch; non-OK responses and fetch errors yield null. A new internal buildReadmeFetchCandidates constructs candidate lists while avoiding duplicates when a specific readmeFilename is provided. resolvePackageReadmeSource first attempts the explicit readmeFilename alone, then falls back to the batched candidates. Tests were added/expanded to verify batching, concurrency behaviour and candidate ordering. No exported signatures changed.

Possibly related PRs

Suggested reviewers

  • danielroe
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The PR description clearly relates to the changeset, explaining the performance optimisation of jsDelivr README fallback probing from sequential to batched-parallel approach with detailed context and rationale.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@trivikr
Copy link
Copy Markdown
Contributor Author

trivikr commented Apr 5, 2026

Also updated PR to fetch provided readme before starting the fallback batch in 72bb0b2

Comment on lines +63 to 66
const matchedReadme = responses.find((response): response is Response => response !== null)
if (matchedReadme) {
return await matchedReadme.text()
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const matchedReadme = responses.find((response): response is Response => response !== null)
if (matchedReadme) {
return await matchedReadme.text()
}
for (const response of responses) {
const text = await response?.text()
if (text) return text
}

I guess it's possible that the readme response is empty, so I wonder if you should do something like this 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants