Skip to content

perf: lazy-load heavy imports in sorts and fs modules#119

Merged
jdalton merged 1 commit intomainfrom
fix/lazy-heavy-imports
Mar 28, 2026
Merged

perf: lazy-load heavy imports in sorts and fs modules#119
jdalton merged 1 commit intomainfrom
fix/lazy-heavy-imports

Conversation

@jdalton
Copy link
Copy Markdown
Collaborator

@jdalton jdalton commented Mar 28, 2026

Summary

  • Lazy-load semver and fastSort in sorts.ts via getter functions
  • Lazy-load del and naturalCompare in fs.ts via getter functions
  • Modules only loaded when the specific functions that need them are first called

Impact

Consumers importing lightweight exports (e.g., isObject from objects, httpJson from http-request) no longer pay the 2.5 MB cost of npm-pack.js at module init time. This reduces the packageurl-js core bundle from 3.3 MB to 178 KB.

Test plan

  • Build passes all validations (145 files, 145 public exports)
  • Lazy getters verified: modules load on first call, cached for subsequent calls

Generated with Claude Code

@jdalton jdalton force-pushed the fix/lazy-heavy-imports branch 5 times, most recently from 11b88cb to 3a3f14f Compare March 28, 2026 22:07
Defer loading of heavy external sub-bundles until first use via lazy
require() getters with /*@__PURE__*/ and /*@__NO_SIDE_EFFECTS__*/
annotations for tree-shaking.

sorts.ts: semver (2.5 MB via npm-pack) and fastSort (8 KB)
versions.ts: semver (2.5 MB via npm-pack)
archives.ts: adm-zip (102 KB) and tar-fs (105 KB)
globs.ts: fast-glob and picomatch (260 KB via pico-pack)
fs.ts: del (260 KB via pico-pack)
spawn.ts: @npmcli/promise-spawn (17 KB)
strings.ts: get-east-asian-width (10 KB)

Impact: consumers importing lightweight exports (isObject, httpJson,
localeCompare, defaultIgnore, readJsonSync, stripAnsi, spawnSync) no
longer pay for heavy externals at module init time. Total deferred:
~494 KB unique, ~2.8 MB including npm-pack chain.
@jdalton jdalton force-pushed the fix/lazy-heavy-imports branch from 3a3f14f to 3cf08f8 Compare March 28, 2026 22:15
@jdalton jdalton merged commit 0859f80 into main Mar 28, 2026
12 checks passed
@jdalton jdalton deleted the fix/lazy-heavy-imports branch March 28, 2026 22:17
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.

1 participant