Build exact Graphile schemas from scoped introspection - #1657
Draft
yyyyaaa wants to merge 1 commit into
Draft
Conversation
This was referenced Aug 5, 2026
yyyyaaa
force-pushed
the
research/graphile-density-stack-04-scoped-graphile-build
branch
from
August 5, 2026 02:57
151d669 to
6314199
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Part 4 of 6 in the draft tenant-density stack: #1654 → #1655 → #1656 → #1657 (this PR) → #1658 → #1659. This is the memory-reduction layer and the security-preserving replacement for #1332–#1334.
The old stack filtered introspection through SQL text substitution, then reused a canonical blueprint by rewriting runtime SQL. This PR changes the algorithm: it parameterizes schema-scoped catalog introspection, computes the catalog dependency closure needed to build an equivalent schema, releases build-only state, and still compiles one Graphile instance against each tenant's exact physical schemas. Runtime SQL is never rewritten.
What changes
makeIntrospectionQuery()and adds a bind-parameter scoped query path; schema names travel as values, not interpolated SQL.stock|scoped-requiredservice behavior. Stock remains the default, and scoped-required fails when a requested schema is missing or closure cannot be satisfied; there is no silent stock fallback.Measured result
Across three fresh-process runs on the 62,298-
pg_classfixture, median retained heap fell from 449.42 MiB to 6.55 MiB, final RSS delta from 1,106.94 MiB to 47.77 MiB, and cold build time from 3,495.95 ms to 130.34 ms. That is 68.60× less retained heap, 23.17× less final RSS, and 26.82× faster cold build, with byte-identical GraphQL SDL and zero recorded mismatches in the comparison.Those are one complete Graphile surface's instance measurements, not complete-customer tenants-per-GiB qualification.
Validation
Why this remains a draft
Scoped mode depends on temporary package patches and must stay off in production until Graphile maintainers review the API and dependency semantics. The complete 1/2/4 GiB tenant ramp, repeated 15-minute mixed workloads, two-hour churn soak, and production-schema extension matrix remain open; #1659 records those gates rather than presenting the old blueprint numbers as current evidence.