Skip to content

perf(claims): intern common claim/header keys in json_to_bound #123

Description

@ZhuchkaTriplesix

Problem

json_to_bound (rust/src/claims.rs:122-126) allocates a fresh PyString for every dict key on every decode, including the same standard claim / header names each time.

Proposal

Use pyo3::intern! (or a small static table) for common keys — exp, iat, nbf, sub, aud, iss, jti, alg, typ, kid — and fall back to a new PyString otherwise. Interned keys also make subsequent dict.get in Python hit the pointer-equality fast path.

Follow-up to consider (measure first): deserialize payload JSON straight into Python objects via a serde visitor, skipping the intermediate serde_json::Value (claims validation would need to move to a borrowed view or a lightweight struct).

Acceptance criteria

  • Common keys are interned
  • Micro-benchmark (decode of a typical 6–10 claim payload) shows improvement; numbers in PR
  • Tests green

Files

  • rust/src/claims.rs

Branch

issue/<N>-intern-claim-keys 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