Skip to content

db: tenancy scope walk costs 26-44 µs per ORM statement #559

Closed

Description

@antosubash

Follow-up from #506 (PR #556).

core_scope.scope_core checks every statement for raw-table references while tenancy names are set. ORM-only statements come back uncloned, but the check still costs about 26–44 µs each (against 0.2 µs when no names are set, and about 10 µs for the old exists() scan).

Profiling: _children accounts for 64% of the walk, and _froms_read / columns_clause_froms for about 12%.

Candidate fix: short-circuit Selects whose raw columns, FROMs and setup-join targets are all ORM-annotated and that have no WHERE/HAVING. Expected saving is about 5 µs per statement. This code is tenancy-critical, so tests must cover Core columns inside an ORM select. Benchmark against the load-test recipe before and after.

https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions