Accept tests root in package.json config#1231
Merged
misrasaurabh1 merged 5 commits intomainfrom Feb 1, 2026
Merged
Conversation
This optimization achieves a **20% runtime improvement** (808μs → 668μs) through two targeted changes:
## Key Optimizations
1. **Module-level `Confirm` import** - Moving `from rich.prompt import Confirm` from inside the function to the module level eliminates repeated import overhead on each function call. The line profiler shows this previously took ~52μs per call, which is now avoided entirely.
2. **Simplified path construction** - Replacing `Path.cwd() / "package.json"` with `Path("package.json")` eliminates an unnecessary OS syscall. The line profiler shows this reduced the path construction time from ~496μs to ~202μs (59% faster on this line alone), saving ~300μs per invocation.
## Why These Changes Matter
- **Import optimization**: Python's import mechanism, even when cached, has overhead. Moving to module-level eliminates this per-call cost completely.
- **Path operation**: `Path.cwd()` makes an OS call (`getcwd()`) every time, while `Path("package.json")` directly creates a path relative to the current directory without the syscall overhead.
## Test Performance
All test cases show consistent improvements:
- Simple cases: 17-46% faster (e.g., empty config test: 58.0μs → 43.6μs)
- Complex validation cases: 21-28% faster (e.g., invalid JSON: 67.3μs → 52.5μs)
- Even large-scale tests with 500+ config keys improved by ~9%
The optimization is particularly effective for scenarios where this function is called multiple times (e.g., during batch operations or repeated validation), as the per-call savings compound. Both changes are semantically equivalent to the original code—they produce identical results while executing faster.
…2026-02-01T12.25.17 ⚡️ Speed up function `should_modify_package_json_config` by 21% in PR #1231 (`js-tests-root`)
Saga4
approved these changes
Feb 1, 2026
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.
No description provided.