Skip to content

perf(core): patch dotenv-expand to improve performance - #7910

Merged
chenjiahan merged 1 commit into
mainfrom
chenjiahan/fix-dotenv-expand-perf
Jun 16, 2026
Merged

chenjiahan merged 1 commit into
mainfrom
chenjiahan/fix-dotenv-expand-perf

Conversation

@chenjiahan

@chenjiahan chenjiahan commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR patches dotenv-expand@13.0.0 with pnpm patch to avoid cloning the full processEnv object for every .env key during expansion.

The patch keeps the same expansion behavior by resolving values lazily with processEnv taking priority over runningParsed, while preserving the existing dependency path instead of forking the package inside Rsbuild.

Comparing upstream dotenv-expand@13.0.0 with the patched package using a large-project-like setup: 2,000 processEnv keys and 200 parsed .env keys.

Version Avg Min Max
Upstream 51.282 ms 49.540 ms 55.521 ms
Patched 0.100 ms 0.060 ms 0.271 ms

Average speedup: ~513x.

Related

@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR patches dotenv-expand@13.0.0 to replace the spread-based { ...runningParsed, ...processEnv } construction inside expandValue() with a lazy getEnvValue() helper. This helper checks whether a key is an enumerable own property of processEnv before falling back to runningParsed, avoiding a full object clone on every expansion. The patch is registered in pnpm-workspace.yaml. A new e2e test case is added under e2e/cases/javascript-api/load-env-expand with .env, .env.production, and src/index.js fixture files, plus an index.test.ts that validates loadEnv correctly expands PUBLIC_* variables when a custom processEnv is supplied and that cleanup() removes the composed variable.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title accurately describes the main change: patching dotenv-expand to improve performance, which is the core objective of the pull request.
Description check ✅ Passed The pull request description clearly explains the performance optimization for dotenv-expand, including benchmarks and the rationale for using pnpm patch.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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 and usage tips.

@chenjiahan chenjiahan changed the title fix(core): patch dotenv-expand performance perf(core): patch dotenv-expand to improve performance Jun 16, 2026
@chenjiahan
chenjiahan merged commit 40ef902 into main Jun 16, 2026
7 checks passed
@chenjiahan
chenjiahan deleted the chenjiahan/fix-dotenv-expand-perf branch June 16, 2026 03:14
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