Skip to content

perf: move filter check before deepcopy in _apply_resource_cb#518

Merged
michael-richey merged 1 commit intomainfrom
perf/filter-before-deepcopy
Apr 8, 2026
Merged

perf: move filter check before deepcopy in _apply_resource_cb#518
michael-richey merged 1 commit intomainfrom
perf/filter-before-deepcopy

Conversation

@michael-richey
Copy link
Copy Markdown
Collaborator

@michael-richey michael-richey commented Apr 7, 2026

Summary

  • Moves the filter() check in _apply_resource_cb to run before deepcopy and lock.acquire(), so filtered-out resources skip both memory allocation and lock contention
  • Adds a lock_acquired boolean to guard the finally block's lock.release() call, preventing RuntimeError on the early-return path for non-concurrent resource types

Context: When syncing with --filter in orgs with thousands of resources, every resource was deepcopied and the lock was acquired before the filter discarded it. This is the first of a series of filter optimization PRs.

Test plan

  • All 211 unit tests pass (python -m pytest tests/unit/)

🤖 Generated with Claude Code

When syncing with --filter, every resource went through deepcopy and
lock acquisition before the filter check discarded it. For orgs with
thousands of resources where only a handful match the filter, this
wasted significant memory on copies that were immediately thrown away.

Move the filter check to run first, before deepcopy and lock.acquire().
Add a lock_acquired boolean to prevent the finally block from releasing
an unacquired lock on the early-return path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@michael-richey michael-richey marked this pull request as ready for review April 7, 2026 20:46
@michael-richey michael-richey requested a review from a team as a code owner April 7, 2026 20:46
@michael-richey michael-richey force-pushed the perf/filter-before-deepcopy branch from 348aba2 to 0887b10 Compare April 7, 2026 21:01
@michael-richey michael-richey merged commit 42b5064 into main Apr 8, 2026
32 checks passed
@michael-richey michael-richey deleted the perf/filter-before-deepcopy branch April 8, 2026 13:48
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.

4 participants