Skip to content

perf(jwt): prebuild JWT Validation and DecodingKey per route #109

Description

@ZhuchkaTriplesix

Context

  • JWT verification in src/dispatch.rs rebuilds jsonwebtoken::Validation (including algs.to_vec()) and DecodingKey on every authenticated request.
  • Route JWT config is static after registration (RouteEntry in src/state.rs).

Problem

Repeated construction of validation state adds CPU on every JWT-protected route.

Proposed change

  • At add_route / freeze, prebuild and store on RouteEntry:
    • DecodingKey (or error if secret invalid — already checked at register time)
    • frozen Validation template with algorithms, iss/aud/leeway
  • Hot path clones cheap handles or uses Arc references.

Files

  • src/state.rs, src/dispatch.rs, src/lib.rs, JWT tests

Acceptance criteria

  • JWT auth behaviour unchanged (expired, wrong alg, iss/aud, cookie vs bearer).
  • No per-request Validation::new + full algorithm vec rebuild.
  • Existing JWT test suite passes.

Expected low-level impact

Lower CPU on every JWT-authenticated request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions