Skip to content

perf: use shallow copy for args/test_cfg in worktree mode#2129

Merged
KRRT7 merged 2 commits intocf-perf-improvementsfrom
cf-perf-shallow-copy-args
May 7, 2026
Merged

perf: use shallow copy for args/test_cfg in worktree mode#2129
KRRT7 merged 2 commits intocf-perf-improvementsfrom
cf-perf-shallow-copy-args

Conversation

@KRRT7
Copy link
Copy Markdown
Collaborator

@KRRT7 KRRT7 commented May 7, 2026

Summary

Replace copy.deepcopy() with copy.copy() in mirror_paths_for_worktree_mode().

Part of #2132 — targeted E2E pipeline performance improvements.

Problem

mirror_paths_for_worktree_mode() deep-copies args (argparse.Namespace) and test_cfg (TestConfig). Deep copy recursively traverses every attribute — expensive for objects with many fields. But both objects contain only immutable types (Path, str, bool) and all fields are reassigned as new objects after copying.

Solution

copy.copy() — creates a new object with shared references to the same immutable values. Safe because every field is subsequently overwritten with a new Path/str, so the original is never mutated through the copy.

Changes

  • codeflash/optimization/optimizer.py: copy.deepcopycopy.copy (2 lines)
  • tests/test_worktree.py: 3 new tests verifying copy independence

Test plan

  • uv run pytest tests/test_worktree.py -v — all 4 tests pass
  • Tests verify originals are preserved after mirroring and mutation

@KRRT7 KRRT7 merged commit 32c627c into cf-perf-improvements May 7, 2026
30 of 33 checks passed
@KRRT7 KRRT7 deleted the cf-perf-shallow-copy-args branch May 7, 2026 03:03
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