Skip to content

perf(dispatch): enable sync short-circuit for sync routes with path parameters (#254) - #261

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
issue-254-sync-path-params
Oct 18, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
issue-254-sync-path-params

Conversation

@ZhuchkaTriplesix

@ZhuchkaTriplesix ZhuchkaTriplesix commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Closes #254

Summary of Changes

  • Route Eligibility (src/lib.rs):
    • Implemented all_path_param_names(&path) to extract all :name and *name parameter names declared in a route template.
    • Updated trivial_sync check: instead of strictly requiring handler_param_names.is_empty(), synchronous routes are eligible for trivial_sync as long as !handler_varkw, no reserved parameter names (query, request, scope, etc.) are present, and handler_param_names == path_params.
    • Routes with **kwargs, non-path parameters, query parameters, request bodies, JWT auth, dependencies, or rate limits correctly defer to the full async pipeline.
  • Sync Dispatch Execution (src/dispatch.rs):
    • In try_rsgi_sync_short_circuit: passed matched params: &matchit::Params to run_trivial_sync_route.
    • In run_trivial_sync_route: when path parameters are present, constructed kwargs: PyDict with coerced path parameters (coercing :name and preserving *wildcard strings as in run_rsgi) and called handler.call((), Some(&kwargs)). When no parameters are present, invoked handler.call0().
  • Tests (tests/test_sync_rsgi_short_circuit.py):
    • Added unit tests verifying synchronous short-circuit (non-awaitable returns with status 200) for:
      • single path parameter (/items/:id)
      • multiple path parameters (/users/:user_id/posts/:slug)
      • catch-all wildcard parameter (/static/*filepath)
      • **kwargs route handlers correctly deferring to async pipeline
      • non-path / query parameter routes properly deferring to async pipeline.

@ZhuchkaTriplesix
ZhuchkaTriplesix force-pushed the issue-254-sync-path-params branch from 8c88d42 to 7a7fad9 Compare October 18, 2026 15:41
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit ff163a8 into dev Oct 18, 2026
17 checks passed
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