Skip to content

perf: lazy-load heavy dependencies in hardhat-utils#8201

Draft
tenderdeve wants to merge 1 commit intoNomicFoundation:mainfrom
tenderdeve:perf/lazy-load-hardhat-utils
Draft

perf: lazy-load heavy dependencies in hardhat-utils#8201
tenderdeve wants to merge 1 commit intoNomicFoundation:mainfrom
tenderdeve:perf/lazy-load-hardhat-utils

Conversation

@tenderdeve
Copy link
Copy Markdown

Summary

Convert top-level imports of 6 heavy dependencies to cached await import(), loaded only on first use:

Dependency File Why
ethereum-cryptography crypto.ts Crypto init overhead on import
fast-equals internal/lang.ts Only needed for deepEqual
rfdc internal/lang.ts Only needed for deepClone
@streamparser/json-node fs.ts Only for readJsonFileAsStream
json-stream-stringify fs.ts Only for writeJsonFileAsStream
env-paths internal/global-dir.ts Rarely called at bootstrap

Follows the cached await import() pattern already established by undici in request.ts in this same package. No public API changes — all consuming functions were already async.

Fixes #8162

Test plan

  • Run npx hardhat --help — should be noticeably faster
  • Run npx hardhat compile — crypto functions still work
  • Run npx hardhat test — all tests pass
  • Verify readJsonFileAsStream / writeJsonFileAsStream still function

Convert top-level imports of 6 heavy dependencies to cached dynamic
imports, loaded only when the consuming function is first called:

- ethereum-cryptography (crypto.ts) — crypto init overhead
- fast-equals (internal/lang.ts) — only needed for deepEqual
- rfdc (internal/lang.ts) — only needed for deepClone
- @streamparser/json-node (fs.ts) — only for readJsonFileAsStream
- json-stream-stringify (fs.ts) — only for writeJsonFileAsStream
- env-paths (internal/global-dir.ts) — rarely called at bootstrap

Follows the cached await import() pattern already used by undici
in this package. No public API changes.

Fixes NomicFoundation#8162
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

⚠️ No Changeset found

Latest commit: fb51e44

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lazy load slow dependencies in hardhat-utils.

2 participants