Skip to content

perf(server-bundle): discover collections via directory listing#501

Merged
atinux merged 2 commits into
mainfrom
perf/discover-collections-via-readdir
Jun 25, 2026
Merged

perf(server-bundle): discover collections via directory listing#501
atinux merged 2 commits into
mainfrom
perf/discover-collections-via-readdir

Conversation

@TheAlexLichter

Copy link
Copy Markdown
Member

🔗 Linked issue

nuxt/nuxt#35390

📚 Description

This PR rewrites discoverInstalledCollections for the typical (non-PnP) case. Now, it finds installed icon sets by listing the @iconify-json scope directory across node_modules instead of resolving all ~220 known collection names one-by-one via local-pkg (this still happens in the PnP case).

The old loop did a full module resolution per missing name, costing ~300-800ms that landed on the cold first dev request because the server bundle is generated lazily.

Local bench

  • discoverInstalledCollections: 862ms → 3ms
  • Cold first-request in server mode: ~2.5s → 2.16s

`discoverInstalledCollections` probed all ~220 known collection names with
`isPackageExists('@iconify-json/<name>')`. Each *missing* name triggers a full
module resolution that walks `node_modules` up to the filesystem root, so on a
project with few/no `@iconify-json` packages this loop takes ~0.8–1.9s.

The server bundle is generated lazily on the first dev request, so that cost
lands on the cold first page load even when no icon is rendered (`server` is the
SSR-default provider). Measured ~862ms on a fresh app; switching the provider to
`iconify` (which skips this path) removed the same ~0.6s.

Instead, list the `@iconify-json` scope directory across `node_modules` (walking
up from each resolve path) once, validate each entry ships an `icons.json`, and
intersect with the known list — behaviour-equivalent, ~3ms. Yarn PnP (no
`node_modules` to read) falls back to the resolver probe.
@TheAlexLichter
TheAlexLichter requested a review from danielroe June 24, 2026 08:37
@pkg-pr-new

pkg-pr-new Bot commented Jun 24, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/icon@501

commit: 6260aab

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

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: 3a94cdac-7377-493f-acc9-4135dda1b022

📥 Commits

Reviewing files that changed from the base of the PR and between 88c290b and 6260aab.

📒 Files selected for processing (1)
  • src/collections.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/collections.ts

📝 Walkthrough

Walkthrough

discoverInstalledCollections in src/collections.ts is refactored to use a found set instead of a single-pass isPackageExists filter. The full-collection early-return path (@iconify/json present) is preserved unchanged. For partial installs, the function now branches: in Yarn PnP environments (process.versions.pnp), it checks each candidate with isPackageExists; in non-PnP environments, it scans node_modules/@iconify-json directories returned by a new iconifyScopeDirs helper, checking for the presence of icons.json per collection. iconifyScopeDirs walks up from each resolved base path, deduplicates discovered scope directories, and returns the resulting array.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: faster collection discovery via directory listing.
Description check ✅ Passed The description matches the changeset and explains the performance motivation and implementation approach.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/discover-collections-via-readdir

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.

@atinux
atinux merged commit c177026 into main Jun 25, 2026
5 checks passed
@atinux
atinux deleted the perf/discover-collections-via-readdir branch June 25, 2026 12:51
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