Skip to content

perf: hoist attr accesses in _update_vscode_summary (#905)#907

Merged
microsasa merged 2 commits intomainfrom
fix/905-hoist-vscode-summary-attrs-c5a6aa15a18dc89a
Apr 10, 2026
Merged

perf: hoist attr accesses in _update_vscode_summary (#905)#907
microsasa merged 2 commits intomainfrom
fix/905-hoist-vscode-summary-attrs-c5a6aa15a18dc89a

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Summary

Closes #905

Optimises the hot loop in _update_vscode_summary by:

  1. Binding accumulator dict fields to locals (rbm, dbm, rbc, rbd) before the loop — converts LOAD_ATTR (slot-descriptor protocol) to LOAD_FAST.
  2. Hoisting repeated req.* accesses (duration_ms, model, timestamp) to local variables within each iteration.
  3. Replacing strftime("%Y-%m-%d") with date.isoformat() on the already-computed date object — avoids re-parsing the format string.

For a log file with 5 000 requests this eliminates ~30 000 LOAD_ATTR ops on acc and ~10 000 on req.

Testing

Added TestUpdateVscodeSummaryLargeScale with 10 500 synthetic VSCodeRequest objects spanning multiple models, categories, and dates. Asserts bit-for-bit correctness of totals, per-model counts/durations, per-category counts, per-date counts, and timestamp bounds. No wall-clock timing — deterministic correctness only, matching the project's perf-test convention.

Generated by Issue Implementer · ● 9.6M ·

Bind _SummaryAccumulator dict fields and repeated VSCodeRequest
attributes to locals before the hot loop, converting LOAD_ATTR to
LOAD_FAST.  Replace strftime("%Y-%m-%d") with date.isoformat() on the
already-computed date object.

Add TestUpdateVscodeSummaryLargeScale with 10 500 synthetic requests to
verify correctness-equivalence of the optimised loop (no wall-clock
timing).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa added the aw Created by agentic workflow label Apr 10, 2026
@microsasa microsasa enabled auto-merge April 10, 2026 19:51
Copilot AI review requested due to automatic review settings April 10, 2026 19:51
@microsasa microsasa added the aw Created by agentic workflow label Apr 10, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Optimizes the hot aggregation loop in src/copilot_usage/vscode_parser.py::_update_vscode_summary, reducing repeated attribute lookups during per-request accumulation when parsing VS Code Copilot Chat logs.

Changes:

  • Hoists accumulator dict attributes to locals and caches repeated VSCodeRequest attribute reads inside the loop.
  • Replaces strftime("%Y-%m-%d") with date.isoformat() for date-key generation.
  • Adds a large-scale correctness test suite intended to validate the optimized loop’s results.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/copilot_usage/vscode_parser.py Refactors _update_vscode_summary to reduce attribute access overhead in the aggregation loop.
tests/copilot_usage/test_vscode_parser.py Adds a new large-scale correctness-oriented test class for _update_vscode_summary.

Replace weak per-date assertions (sum + format check) with exact
expected mapping equality to properly verify the full date distribution
from _update_vscode_summary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Commit pushed: 57371f6

Generated by Review Responder

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@microsasa microsasa added the aw-quality-gate-approved Quality gate approved the PR label Apr 10, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low-impact performance optimization of a private internal function (_update_vscode_summary). Changes hoist attribute accesses to locals and replace strftime with isoformat — semantically equivalent, no API/contract changes. New TestUpdateVscodeSummaryLargeScale test class (3 methods, 10.5k synthetic requests) thoroughly validates correctness. All CI checks pass. Auto-approving for merge.

@microsasa microsasa merged commit 0e2808b into main Apr 10, 2026
9 checks passed
@microsasa microsasa deleted the fix/905-hoist-vscode-summary-attrs-c5a6aa15a18dc89a branch April 10, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow aw-quality-gate-approved Quality gate approved the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][perf] vscode_parser._update_vscode_summary: bind accumulator dict attributes to locals before hot inner loop

2 participants