Skip to content

perf: header_get_lax does up to 3 Python attribute/dict lookups per header read #220

Description

@ZhuchkaTriplesix

Where: src/params.rs:108-134 (header_get_lax), called for authorization, cookie, content-type, origin, and the rate-limit key header — several times per request.

The function tries up to 3 case variants (name, lowercase, uppercase) against a PyDict downcast, then falls back to up to 3 getattr("get").call1(...) attempts, allocating a new lowercase/uppercase String each time. Granian's RSGI headers are already lowercase per spec, so in the common case this does far more work (and allocation) than a single lookup needs.

Fix direction: try the exact/lowercase name once; only fall back to case-insensitive scanning if that misses, and avoid allocating both a lowercase and uppercase copy up front.

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions