Title: Performance [P2]: Cache type-discovery signature structure by berndverst · Pull Request #207 · microsoft/durabletask-python · GitHub
Open Graph Title: Performance [P2]: Cache type-discovery signature structure by berndverst · Pull Request #207 · microsoft/durabletask-python
X Title: Performance [P2]: Cache type-discovery signature structure by berndverst · Pull Request #207 · microsoft/durabletask-python
Description: Summary durabletask/internal/type_discovery.py cached resolved type hints, but _input_annotation() and activity_output_type() still called inspect.signature() and re-filtered positional parameters on every invocation. Discovery runs once per work item — activity execution, entity operation, and every orchestration replay of call_activity — so small, high-frequency handlers repeatedly paid reflection costs. The signature structure (positional parameters in declaration order plus the return annotation) and the resolved annotations are a pure function of the callable, so they are now computed once and memoized in a bounded functools.lru_cache (same maxsize=2048 bound and rationale as the existing resolved-hints cache). Correctness DataConverter.can_reconstruct() is not part of the cached value. It is still evaluated on every call, so a different — or stateful — converter continues to produce its own per-call decision for the same function. All existing resolution semantics are preserved bit-for-bit: unannotated parameters, *args / **kwargs and keyword-only parameters (still not positional inputs), Any, PEP 563 / string postponed annotations that cannot be resolved, plain functions vs. unbound entity methods, and the conservative fallback to the raw payload when resolution fails. A dedicated _NO_ANNOTATION sentinel is used instead of None so that a literal None annotation still reaches the converter exactly as before. Callables that cannot be used as a cache key (unhashable) fall back to an uncached computation, so caching never narrows the set of callables that discovery supports. Previously such callables raised TypeError from the hints cache. No public API change, no renames, no changed import paths. One observable behavior change, surfaced in review: a handler that is an unhashable callable — most realistically a @dataclass with __call__, since dataclasses default to eq=True and so set __hash__ = None — previously raised TypeError: unhashable type out of the memoized hint lookup during type discovery. Such handlers reach the worker through add_named_activity() / add_named_orchestrator() / add_named_entity(), which take an explicit name and so do not require __name__. They now resolve their annotations normally. This is covered by a CHANGELOG entry under Unreleased / FIXED and pinned by a test through the public registration API. Performance Steady-state cost per call for def act(ctx, order: Order) -> Order (dataclass input/output, caches warm, 100k iterations): helper before after speedup activity_input_type 10.190 us 0.885 us 11.5x activity_output_type 9.119 us 0.813 us 11.2x The residual ~0.8 us is dominated by can_reconstruct(), which is intentionally still per-call. Verification Core unit tests: pytest tests/durabletask -q --ignore-glob="*_e2e.py" -> 688 passed, 7 skipped (baseline on main was 681 tests; the 7 new tests account for the difference). Provider unit tests: pytest tests/durabletask-azuremanaged/test_sandboxes_extension.py tests/durabletask-azuremanaged/test_durabletask_grpc_interceptor.py -q -> 42 passed. flake8 clean on both changed files; pyright (strict, project config) reports 0 issues for durabletask/internal/type_discovery.py. New tests in tests/durabletask/test_type_discovery.py (all 7 verified to fail or be meaningless against the pre-change implementation): inspect.signature() is invoked once per callable and never again, for both the input and output helpers and for class-based entity operations. Priming the cache with a converter that recognizes a type and then querying with the default converter returns the correct different answer (both orders, input and output). A stateful converter that flips its can_reconstruct answer between calls is honored on every call. The converter is consulted on every call, and never for unannotated parameters. Unhashable callables still resolve. Fixes #189
Open Graph Description: Summary durabletask/internal/type_discovery.py cached resolved type hints, but _input_annotation() and activity_output_type() still called inspect.signature() and re-filtered positional parameters ...
X Description: Summary durabletask/internal/type_discovery.py cached resolved type hints, but _input_annotation() and activity_output_type() still called inspect.signature() and re-filtered positional parameters ...
Opengraph URL: https://github.com/microsoft/durabletask-python/pull/207
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a695c0d1-d12d-ed64-fe51-333a4c3fa186 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A2D8:2CAD0F:43483:54621:6AFE414C |
| html-safe-nonce | 93cfc3716335ea2fb180721829d70ae5a63ec195dff6aae076b30c11120bc79b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMkQ4OjJDQUQwRjo0MzQ4Mzo1NDYyMTo2QUZFNDE0QyIsInZpc2l0b3JfaWQiOiI5MDc3MTIxNjY3NzEyMzAzNDM2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f2dfbb3c56dd77785258c4c88671a2d94b8958745b59d317f5d6275948218617 |
| hovercard-subject-tag | pull_request:4139791674 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/microsoft/durabletask-python/pull/207/files |
| twitter:image | https://avatars.githubusercontent.com/u/4535280?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4535280?s=400&v=4 |
| og:image:alt | Summary durabletask/internal/type_discovery.py cached resolved type hints, but _input_annotation() and activity_output_type() still called inspect.signature() and re-filtered positional parameters ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | f1a5901e2377b0af2a0b303f9528678f1475d04b9219dca1e993344196eaa07c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/microsoft/durabletask-python git https://github.com/microsoft/durabletask-python.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 627664515 |
| octolytics-dimension-repository_nwo | microsoft/durabletask-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627664515 |
| octolytics-dimension-repository_network_root_nwo | microsoft/durabletask-python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c4447fdce9ed0f33af959d2b6680d0bc18212a6a |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width