Skip to content

perf(api): trim Python overhead on the plain decode fast path #122

Description

@ZhuchkaTriplesix

Problem

For HS256 the Python wrapper costs about as much as the native work:

µs/call
_oxyjwt.decode (native) 1.30
oxyjwt.decode (fast path) 2.14

The fast path in PyJWT.decode / decode_complete (python/oxyjwt/api_jwt.py:206-218, :257-272) calls _is_plain_decode (9 args), _require_detached_payload_for_rfc7797, and _validate_claims_default, which calls time.time() and re-checks exp even though Rust already validated it.

Proposal

  • Inline _is_plain_decode and the ".." in token pre-check into the fast path.
  • In _validate_claims_default, only re-check exp in Python when it is not an int (for ints Rust exp <= now_int and Python exp <= time.time() are equivalent; for floats Rust rounds while Python truncates, so that case must stay for PyJWT parity).
  • Call time.time() only when iat or a non-int exp is present.

Acceptance criteria

  • HS256 oxyjwt.decode overhead over native reduced by ≥ 30%
  • tests/test_decode_fast_path.py, tests/test_parity_pyjwt.py green; add a test for float exp boundary parity

Files

  • python/oxyjwt/api_jwt.py

Branch

issue/<N>-python-fast-path-overhead from dev

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2Nice to have or post-1.0performanceThroughput and latency

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions