Skip to content

feat: add async support for @bench decorator and bench.arecord() - #71

Merged
alubbock merged 3 commits into
mainfrom
feat/async-support
Mar 14, 2026
Merged

alubbock merged 3 commits into
mainfrom
feat/async-support

Conversation

@alubbock

Copy link
Copy Markdown
Owner

Summary

  • @bench now detects async def functions via inspect.iscoroutinefunction and returns a true async def wrapper — await decorated_fn() works in any async framework; the sync path is completely unchanged
  • bench.arecord(name) returns _AsyncContextManagerRun for async with blocks, mirroring bench.record() for sync code
  • MBLineProfiler raises NotImplementedError at decoration time when applied to an async function (line profiling of coroutines is unsupported)
  • All mixins, static fields, output sinks, iterations, and warmup behave identically to the sync path
  • 11 new pytest-asyncio tests; pytest-asyncio added to test dependencies with asyncio_mode = "auto"
  • New docs page docs/user-guide/async.md covering usage, timing caveat, and MBLineProfiler incompatibility

- __call__ detects coroutine functions via inspect.iscoroutinefunction and
  returns an async def wrapper (functools.wraps preserved); sync path unchanged
- MBLineProfiler raises NotImplementedError at decoration time for async funcs
- bench.arecord(name) returns _AsyncContextManagerRun for use with async with
- 11 new pytest-asyncio tests covering: standard fields, iterations, warmup,
  exception capture, MBReturnValue, MBFunctionCall, arecord, MBLineProfiler guard,
  and monitor thread
- docs/user-guide/async.md with usage guide and timing caveat
- pytest-asyncio added to test optional-dependencies; asyncio_mode = "auto"
asyncio_mode = "auto" in pyproject.toml generates a warning and is not
recognised until after pytest-asyncio is loaded. In strict mode (the
default in pytest-asyncio >= 0.21) async tests require an explicit mark.
Adding @pytest.mark.asyncio to each async test makes them work with both
auto and strict mode without relying on the config key.
Replaces the manually maintained pip install list with pip install -e .[test]
so CI automatically picks up any future test dependency changes.
@alubbock
alubbock merged commit b517797 into main Mar 14, 2026
20 checks passed
@alubbock
alubbock deleted the feat/async-support branch March 14, 2026 22:16
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