Repository navigation
perf(transform): copy events one level deep in filter_period_intersect - #203
Conversation
_replace_event_period deep-copied every intersected event. On a year of synthetic data (322k window, 54k web events) that deepcopy is the largest single cost of aw-webui's Activity query in the Python server. Build the result Event directly with a one-level copy of data, the same isolation aw_query's _copy_events gives transforms (they only set top-level keys). Year query, same interpreter, in-process: 15.3s -> 12.9s. Refs ActivityWatch/activitywatch#1545 Git-Session-Id: ccc0b6a5-3ef4-47ad-b308-b87ee9aef8e8
[Medium impact] This PR appears safe to merge. Summary
Reviews (1) · Last reviewed commit: "perf(transform): copy events one level d..." · Reviewed by Greptile |
|
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. |
🤖 AI code reviewReplaces Safe to merge — no P0/P1 findingsConfidence 5/5 ✅ No findings. The diff looks correct to me on this pass. Files changed (2) — the diff as I read it
Reviewed Maintainer commands
|
_replace_event_perioddeep-copied every event thatfilter_period_intersectreturns. With a year of data that deepcopy is the largest single cost of aw-webui's Activity query in the Python server: the query intersects all window events with not-AFK, and all web events with the browser window.This change builds the result
Eventdirectly, with a one-level copy ofdata. That gives the same isolationaw_query's_copy_eventsgives transforms (#172): transforms only set top-level keys.Measurement. I ran the aw-webui
fullDesktopQuery-shaped year query in-process against a synthetic year: 321,781 window, 6,146 AFK and 53,756 web events, the same data as in ActivityWatch/activitywatch#1545. One Python 3.9 interpreter, with a fetch function shared by every checkout so that only aw-core code differs. Medians of 3 runs:6a58ec55d34ffe5d34ffe+ this changeThe ~3s regression between those two pins is spread over several correctness changes rather than one bug:
_copy_events(#172) costs about 0.9s, JSON merge keys (#173) about 0.5s, WHATWG URL parsing (#173) about 0.3s, and flood normalization (#143/#145/#165) about 0.4s. This PR doesn't revert any of them. It removes a long-standing cost that is larger than all of them together.Test:
test_filter_period_intersect_copies_eventspins that results are new events whosedataand period can change without touching the input. The full suite passes locally (pytest tests/).