Skip to content

perf(transform): copy events one level deep in flood and merge_subwatcher_fields - #204

Merged
ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:perf/flood-merge-one-level-copy
Nov 17, 2026
Merged

ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:perf/flood-merge-one-level-copy

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Follow-up to #203, which removed the deepcopy in filter_period_intersect for the year-query slowdown (ActivityWatch/activitywatch#1545). Two deepcopy hot spots remain on master.

Change

  • flood(): replace deepcopy(events) of the whole list with new Events and a dict(data) copy. flood only reassigns timestamp/duration; it never mutates data in place.
  • merge_subwatcher_fields(): the per-event deepcopy(base) calls become the same one-level copy (_copy_event). The code only assigns top-level data keys. Values injected from subwatcher events are still deepcopyd, so injected nested values stay isolated.
  • Nested values inside a copied data dict are now shared with the input (as in perf(transform): copy events one level deep in filter_period_intersect #203); none of these transforms mutate them.

Measurement

Synthetic, same interpreter, median of 3 (not the activitywatch year-query harness, which needs built server binaries):

before after
flood(), 150k events 1.58s 0.77s
merge_subwatcher_fields, 4k base × 1.5k sub 1.34s 1.18s

merge_subwatcher_fields is dominated by its per-base scan of subwatcher events, so the copy change is a small win there; flood() halves.

Tests

Full suite: 496 passed, 5 skipped. Added two isolation tests (input events and their data untouched, outputs are distinct objects). They also pass on the old deepcopy code (it isolated fully), so they guard the behaviour rather than prove the speedup.

Note

#202 also edits flood.py (adjacent hunk near the sort line); whichever lands second needs a trivial rebase.

…cher_fields

Git-Session-Id: bc912f6d-20ed-4a29-b4c4-9e8bdcbb87bb
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Review guide (auto-posted)

Structured warm-up for reviewers — what changed, what to run, where to look.

Key files

  • tests/test_transforms.py (+36/-0, Δ36)
  • tests/test_flood.py (+29/-0, Δ29)
  • aw_transform/merge_subwatcher_fields.py (+19/-6, Δ25)
  • aw_transform/flood.py (+8/-2, Δ10)

Suggested verification

  • uv run pytest tests/test_flood.py tests/test_transforms.py -q
  • make typecheck

Known risks / watch points

  • No automatic high-risk tags; use file list + diff for judgment.

Suggested review focus

  • Confirm behavior matches the PR description acceptance criteria.
  • Skim the largest diffs first (listed above).
  • If CI is green, spot-check the highest-risk paths called out here.

Generated by scripts/github/pr-warmup-review-guide.py for #204.

@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Replaces full event copies with new Event objects and new top-level data dictionaries in flood() and merge_subwatcher_fields().

  • Flood results use fresh events with their own top-level data dictionaries.
  • Merged event segments get fresh top-level data dictionaries.

Reviews (1) · Last reviewed commit: "perf(transform): copy events one level d..." · Reviewed by Greptile

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@TimeToBuildBob

TimeToBuildBob commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI code review

In aw_transform/flood.py, flood() replaces deepcopy(events) with new Event instances and shallow copies of their data dictionaries. merge_subwatcher_fields() adds _copy_event() and uses it instead of deep-copying base events, while retaining deep copies of injected subwatcher values. Two tests check input preservation, distinct output objects and dictionaries, and isolation of injected nested values.

Safe to merge — no P0/P1 findings

Confidence 5/5

✅ No findings. The diff looks correct to me on this pass.

Files changed (4) — the diff as I read it
  • aw_transform/flood.py — Replaces the list-wide deepcopy with per-event construction and dict(e.data), and removes the deepcopy import.
  • aw_transform/merge_subwatcher_fields.py — Adds _copy_event() and replaces four base-event deepcopy sites with shallow data copies, retaining deepcopy for injected values.
  • tests/test_flood.py — Adds a test checking input preservation, merged output identity, distinct data dictionaries, and isolation of a top-level output assignment.
  • tests/test_transforms.py — Adds a test checking merge input preservation, isolation of injected nested values, and distinct event and data objects for empty-key passthrough.

Reviewed b0391b1017ff · panel: codex:gpt-6.1-sol + claude-code:sonnet · subscription engine · 18s · about this reviewer

Maintainer commands

@TimeToBuildBob review (own line) — fresh review · @TimeToBuildBob fix — a worker acts on the findings. Once per comment; 👀 = received.

@ErikBjare
ErikBjare merged commit 75ccb41 into ActivityWatch:master Nov 17, 2026
7 checks passed
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.

2 participants