perf: lazy-load heavy imports in sorts and fs modules#119
Merged
Conversation
11b88cb to
3a3f14f
Compare
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.
3a3f14f to
3cf08f8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
semverandfastSortinsorts.tsvia getter functionsdelandnaturalCompareinfs.tsvia getter functionsImpact
Consumers importing lightweight exports (e.g.,
isObjectfrom objects,httpJsonfrom 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
Generated with Claude Code