Skip to content

Accept tests root in package.json config#1231

Merged
misrasaurabh1 merged 5 commits intomainfrom
js-tests-root
Feb 1, 2026
Merged

Accept tests root in package.json config#1231
misrasaurabh1 merged 5 commits intomainfrom
js-tests-root

Conversation

@mohammedahmed18
Copy link
Contributor

No description provided.

mohammedahmed18 and others added 3 commits February 1, 2026 14:14
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`)
@misrasaurabh1 misrasaurabh1 merged commit 4803f26 into main Feb 1, 2026
9 of 24 checks passed
@misrasaurabh1 misrasaurabh1 deleted the js-tests-root branch February 1, 2026 20:29
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.

3 participants