Skip to content

Cache parsed package info in nimblemeta.json to avoid re-parsing inst…#1718

Open
bung87 wants to merge 2 commits into
nim-lang:masterfrom
bung87:cache-pkginfo-metadata
Open

Cache parsed package info in nimblemeta.json to avoid re-parsing inst…#1718
bung87 wants to merge 2 commits into
nim-lang:masterfrom
bung87:cache-pkginfo-metadata

Conversation

@bung87

@bung87 bung87 commented May 28, 2026

Copy link
Copy Markdown
Contributor

…alled packages

This fixes the performance issue where nimble reevaluates every package in the nimble directory on each command, causing slow builds when the global nimble dir has many packages (#1331). same to #1486

Changes:

  • Extend PackageMetaData with requires, features, srcDir, paths, preHooks, postHooks, and nestedRequires fields
  • Save parsed info to nimblemeta.json during installation
  • Load cached info in getInstalledPackageMin to skip re-parsing
  • Skip toRequiresInfo for installed packages that have cached data
  • Add backward-compatible initFromJson for PackageMetaData

bung87 added 2 commits May 29, 2026 03:16
…alled packages

This fixes the performance issue where nimble reevaluates every package
in the nimble directory on each command, causing slow builds when the
global nimble dir has many packages (nim-lang#1331).

Changes:
- Extend PackageMetaData with requires, features, srcDir, paths,
  preHooks, postHooks, and nestedRequires fields
- Save parsed info to nimblemeta.json during installation
- Load cached info in getInstalledPackageMin to skip re-parsing
- Skip toRequiresInfo for installed packages that have cached data
- Add backward-compatible initFromJson for PackageMetaData
…tolerance

- install.nim: Use serializeRequires that matches toJsonHook behavior:
  * verAny: just name (e.g. "file://../depfile")
  * verSpecial: name + ver without space (e.g. "nim#head")
  * others: name + space + ver (e.g. "nim >= 1.2")
  This fixes the round-trip parsing issue where  produced
  "name@ver" format that parseRequires could not handle.

- packageinfo.nim: Wrap parseRequires in try/except so corrupted or
  old-format cache data doesn't crash nimble. Falls back to normal
  parsing when cache deserialization fails.

- packagemetadatafile.nim: Restore custom initFromJson for PackageMetaData
  to tolerate missing fields in old nimblemeta.json files, preserving
  backward compatibility with packages installed by older nimble versions.
@jmgomez

jmgomez commented May 29, 2026

Copy link
Copy Markdown
Collaborator

The declarative parsing shouldnt take enough time to worth to cache it. Did you benchmark it?

@bung87

bung87 commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

I didn't get correct performance result due to something wrong when running, but I have 200+ packages installed, so even the declarative parsing is fast, I still dont wanna waste time

@jmgomez

jmgomez commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Well, you should use local which will be the default and has a cache already in place no need for yet another one

@bung87

bung87 commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

I only use couple times due to network condition, most times use the global mode.

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