Skip to content

Release 1.0.1: keep timings consistent after warnings-as-errors and mid-section clears - #16

Merged
seba2390 merged 2 commits into
mainfrom
fix/1.0.1
Sep 30, 2026
Merged

seba2390 merged 2 commits into
mainfrom
fix/1.0.1

Conversation

@seba2390

Copy link
Copy Markdown
Owner

What does this change?

Two bug fixes found in a post-1.0 review, plus small packaging hardening. No API changes.

1. Warnings-as-errors re-corrupted the stack. stop_timer emitted its RuntimeWarning before recording the exit. Under filterwarnings = ["error"] (or python -W error), the warning raised from __exit__, replaced the user's exception, and left the active stack pointing at the abandoned section. That is the exact failure 1.0.0 set out to fix. The exit is now recorded and the stack unwound first, then the warning is emitted.

2. Clearing inside an outer section broke totals. The README recommends clearing periodically in long-running loops, which usually sit inside an outer section. The children then have no recorded parent, and the report showed:

Total time: 0.0000 s.

..  load: 0.0125 s (0.00%)
..  train: 0.0249 s (0.00%)

Totals now count every section without a recorded parent (the same roots _ordered_by_hierarchy already used), and the report indents by tree depth instead of path length. get_total_time(), the report and the JSON total_time share one helper, _top_level_time. Category totals already handled this case.

Packaging: hatchling>=1.27 (the first release with PEP 639 license-files), and Dependabot groups monthly updates into one PR per ecosystem.

Performance

Recording code is unchanged apart from the order of the warning branch. Overhead benchmark (--number 100000 --repeat 9, CPython 3.11, macOS arm64), ns/op:

Operation Before After
New context 1208 1188
Reused context 1046 1053
Decorated call 1106 1098
Five nested contexts 5616 5665
Decorated await 1182 1178
Total time, 1,000 sections 57798 55982
JSON, 1,000 sections 1047073 1048818

All differences are within ±3%, which is run-to-run noise.

Checklist

  • uv run pytest --cov passes (96 tests, 100% statement and branch coverage)
  • uv run ruff check and uv run ruff format --check pass
  • uv run basedpyright passes (0 errors, 0 warnings)
  • Behaviour changes are covered by a test (an existing test asserted the buggy 0.00% output and was corrected)
  • CHANGELOG.md updated (as ## [1.0.1])

Exiting a section past a still-active inner one emitted its RuntimeWarning before
recording the exit. With warnings configured as errors, common under pytest's
filterwarnings = ["error"], the warning raised from __exit__, replaced the exception
propagating from the timed block, and left the active stack pointing at the abandoned
section. The exit is now recorded and the stack unwound before the warning is emitted.

Clearing timings while a section is active leaves its children without a recorded
parent. The report ordered them as roots but indented them by path length, beneath an
unrelated section, and every total counted only single-element paths, so a periodic
clear inside an outer section reported a total of 0 and 0.00% for everything. Totals
now count every section without a recorded parent, the same roots the hierarchy
ordering uses, and the report indents by tree depth. get_total_time, the report and
the JSON total share one definition.

Recording is untouched and the overhead benchmark is unchanged within noise.
Require hatchling>=1.27, the first release supporting the PEP 639 license-files
metadata the project declares, and group Dependabot's monthly updates into one pull
request per ecosystem.
@seba2390
seba2390 merged commit 0202eab into main Sep 30, 2026
18 checks passed
@seba2390
seba2390 deleted the fix/1.0.1 branch September 30, 2026 20:35
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.

1 participant