Skip to content

perf(progress): speed up snapshot emission -- 7.7% less time - #1066

Merged
vgrem merged 1 commit into
vgrem:masterfrom
dexhunter:perf/progress-snapshot
Nov 4, 2026
Merged

vgrem merged 1 commit into
vgrem:masterfrom
dexhunter:perf/progress-snapshot

Conversation

@dexhunter

@dexhunter dexhunter commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

  • Speed up ProgressTracker._emit when worker threads report completed work.
  • Use positional snapshot fields and one callback lookup per emission.
  • Progress benchmark: 578.48 ms -> 533.97 ms, 7.7% less time.
  • Tested with python -m pytest -q: 566 passed, 976 skipped, and 133 subtests passed.

What & Why

Each emission currently reads the callback attribute twice and passes four field names to Progress.
The change keeps a local callback and passes the same fields in constructor order.
The existing constructor still creates a fresh snapshot with the original values and item references.

Validation

Measured on Linux with Python 3.12.13, using an isolated CPU core.
Progress times are medians across three runs, each with 13 comparisons.
Each sample runs 360 batches of ten workers making 100 advances, plus callback behavior checks.
The three runs reduced time by 7.6–8.6%.

Situation Before After Change
Threaded progress reporting, 360 batches 578.48 ms 533.97 ms 7.7% less time
2,000 synchronous requests, per request 17.20 µs 17.43 µs +1.3%, overlapping ranges
2,000 asynchronous requests, per request 87.52 µs 89.71 µs +2.5%, overlapping ranges
2,000 async requests with inline setup, per request 17.10 µs 17.18 µs +0.5%, no material change

Request timings use the repository's existing loopback benchmark: medians of three runs, each taking the best of five repetitions.
Before/after order was reversed in the second run.
These request paths do not emit progress; no speedup is claimed for them.
Inline setup ranged from 17.04–17.17 µs before and 17.00–17.20 µs after.

Run the original threaded workload test and the request benchmark with:

python -m pytest tests/unit/test_runtime_retry.py::test_thread_safe_advances_sum_to_total
PYTHONPATH=. python scripts/bench_async_overhead.py --requests 2000 --repeat 5

The focused suite passed all 111 tests:

python -m pytest tests/unit/test_runtime_retry.py tests/unit/test_dataframe_import.py tests/unit/test_converters.py tests/unit/test_runtime_async.py

Ruff 0.16.10 lint and formatting checks passed across the repository.
Pyright reported nine errors and one warning, identical on the baseline and candidate; none concern the changed method.

Why this is safe and easy to maintain

The change stays in one short method and keeps the public API unchanged.
Callbacks are still checked for callability, and their exceptions still reach the caller.
Existing retry, import, converter, and async tests cover the callers.
Separate behavior checks cover callback replacement, falsey callables, re-entry, and snapshot identity.

Summary

Scope: office365/runtime/operations.py only; no dependencies or configuration changes.

Type of change

  • Bug fix
  • New feature
  • Documentation / examples
  • Refactor / internal

Checklist

  • Ruff lint and formatting pass (run with uvx --from ruff==0.16.10).
  • uv run pyright is clean.
  • Offline pytest suite passes (run with the existing Python environment).
  • uv run mkdocs build --strict passes (docs/examples unchanged).
  • Added/updated tests under tests/unit where practical.
  • Linked the related issue.

AI assistance

This PR was prepared with AI assistance from Aiden. Candidates were tracked with Weco Observe.

Weco share link: https://dashboard.weco.ai/share/rwjyR5jN8oFIqzeQd5u-GsYxAqKNXt4M

Use positional Progress arguments and bind the callback once per emission.
Keep fresh snapshots and per-emission callability checks.

Co-Authored-By: Aiden <[email protected]>
@vgrem
vgrem merged commit 2beb0ef into vgrem:master Nov 4, 2026
vgrem added a commit that referenced this pull request Nov 7, 2026
…author

The Unreleased section ran 1,463 lines for 175 changes. Each bullet carried the
mechanism — which module was folded into which, which helper replaced which — so
a reader looking for "what changes for me" had to reconstruct the answer from the
commit that made it.

Nothing was dropped that a caller can observe. What went is the narration of how
the change was reached: the second design, the internal seam that reappeared, the
count of lines deleted. What stayed is the fact, the one clause of why it matters,
and the names a caller types. 175 bullets became 149, and the four permissions
sections read as what they are: one declaration surface, counted once.

Four merged PRs had no line at all — the serialization, path-building, timestamp
and progress fast paths (#1069, #1068, #1067, #1066), each now stated as the
number it buys. The page payload fix (0117ecc) is stated too, because it is the
answer to a reported 2019-farm refusal: an emptied nested value is no longer sent.
The single-quote escape (#1053) is not here — it shipped in 3.3.0, which already
records it.
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