Skip to content

⚡ perf(benchmark): module-scope fixtures for faster benchmark runs (#171)#396

Merged
sodre merged 9 commits into
mainfrom
perf/171-benchmark-fixture-scope
Feb 16, 2026
Merged

⚡ perf(benchmark): module-scope fixtures for faster benchmark runs (#171)#396
sodre merged 9 commits into
mainfrom
perf/171-benchmark-fixture-scope

Conversation

@sodre

@sodre sodre commented Feb 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Add module-scoped moto fixtures (mock_dynamodb_module, benchmark_limiter) and a BenchmarkEntities dataclass to tests/benchmark/conftest.py so entity/table setup runs once per test file instead of once per test
  • Switch test_throughput.py, test_latency.py, and test_operations.py to use pre-warmed benchmark_entities for warm-path measurements, while capacity and optimization-comparison tests keep function-scoped sync_limiter
  • Add fixture scope selection guidance to .claude/rules/testing.md with a decision table and module-scoped moto tips
  • Include implementation plan document in docs/plans/

Test plan

  • uv run pytest tests/benchmark/ -o "addopts=" -v --benchmark-only — all benchmark tests pass
  • uv run pytest tests/unit/ -v — no regressions in unit tests
  • Verify benchmark run time is reduced (baseline ~9.5s, target ~30-50% faster)

Closes #171

🤖 Generated with Claude Code

sodre and others added 7 commits February 15, 2026 21:19
Document the design for module-scoping benchmark fixtures to reduce
setup overhead and enable steady-state warm-path measurements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7-task plan covering module-scoped moto fixtures, BenchmarkEntities
dataclass, test file updates (throughput, latency, operations),
verification, and documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ies (#171)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…171)

Replace function-scoped sync_limiter with module-scoped benchmark_entities
in all throughput benchmark tests. Tests now use pre-warmed entity IDs
instead of creating entities inline, measuring steady-state performance
without cold-start overhead.

- TestThroughputBenchmarks: use benchmark_entities.flat for standalone ops
- TestThroughputWithHierarchy: use benchmark_entities.parents/children
  instead of hierarchy_limiter fixture
- Remove unused `from typing import Any` import

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace function-scoped sync_limiter with module-scoped benchmark_entities
in all latency benchmarks. Tests now use pre-warmed entity IDs from the
shared BenchmarkEntities dataclass, eliminating per-test entity creation
and table setup overhead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…171)

Switch TestAcquireReleaseBenchmarks, TestTransactionOverheadBenchmarks,
TestCascadeOverheadBenchmarks, and TestConcurrentThroughputBenchmarks to
use module-scoped benchmark_entities for steady-state measurement.

Keep TestConfigLookupBenchmarks and TestOptimizationComparison on
function-scoped sync_limiter / sync_limiter_no_cache for clean-state
optimization comparisons.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sodre sodre added this to the v0.10.0 milestone Feb 16, 2026
@sodre sodre added testing Test coverage performance Performance optimization labels Feb 16, 2026
@codecov

codecov Bot commented Feb 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.88%. Comparing base (1cbe2e3) to head (9924227).
⚠️ Report is 10 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #396   +/-   ##
=======================================
  Coverage   91.88%   91.88%           
=======================================
  Files          33       33           
  Lines        7435     7435           
=======================================
  Hits         6832     6832           
  Misses        603      603           
Flag Coverage Δ
doctest 29.41% <ø> (ø)
e2e 42.35% <ø> (-0.02%) ⬇️
integration 51.37% <ø> (ø)
unit 91.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sodre sodre marked this pull request as ready for review February 16, 2026 05:19

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.40.

Benchmark suite Current: e413927 Previous: 1cbe2e3 Ratio
tests/benchmark/test_operations.py::TestOptimizationComparison::test_stored_limits_cache_disabled 136.49090751013046 iter/sec (stddev: 0.03293390179940827) 229.52741614495207 iter/sec (stddev: 0.00009611893914352546) 1.68

This comment was automatically generated by workflow using github-action-benchmark.

Tests only use indices 0-12. Creating 111 entities dominated module
setup time (~4s). With 15 flat + 11 hierarchy = 26 entities, module
setup drops to ~1.3s.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sodre sodre merged commit 0edbb57 into main Feb 16, 2026
16 checks passed
@sodre sodre deleted the perf/171-benchmark-fixture-scope branch February 16, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance optimization testing Test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

⚡ Fix benchmark_entities fixture scope for faster benchmark runs

1 participant