Add upstream-shaped scoped introspection plugin - #1763
Draft
Zetazzz wants to merge 12 commits into
Draft
Conversation
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.
Summary
This is an upstream-shaped, opt-in alternative to #1719. It copies the exact Crystal release sources pinned by CNC (
pg-introspection@1.0.1,graphile-build-pg@5.1.3) and keeps the upstream package boundaries while adding a scoped query and replacement introspection plugin.Unset/
falseuses untouched upstream stock introspection.GRAPHILE_SCOPED_INTROSPECTION=truedynamically installsScopedIntrospectionPreset;GRAPHILE_SCOPED_INTROSPECTION_JITindependently controls the introspection session JIT setting and defaults tofalse.Architecture and configuration
pg-introspection: parameterized recursive schema/dependency-closure query,all/dependency-closurecatalog type policy, and extension capability retention.graphile-build-pg: complete CNC-ownedPgScopedIntrospectionPlugin, upstream lifecycle/watch/entity behavior, namespace and missing-type fail-closed guards, and pinned upstream contract sentinel.preset.gather, keyed by PostgreSQL service name. PG service objects are no longer mutated or extended with CNC-only fields.gather.pgScopedIntrospectionand keeps JIT inpgSettingsForIntrospection.ConstructivePresetremains unchanged.Equivalent direct configuration:
Presence of a service entry enables scoped introspection for that service. Services without an entry remain stock, mixed stock/scoped services are supported, and an unknown configured service fails closed.
Benchmark arms differ only by upstream
PgIntrospectionPlugin/stock query versusScopedIntrospectionPreset/scoped query. They do not loadConstructivePreset, retirement/disposers, governor/cache limits, routing, or admission plugins.Correctness coverage
The real PostgreSQL dependency-closure fixture covers cross-schema enum/domain/composite/range/multirange types, function signatures, ordinary and
pg_trgmindexes, extension metadata, a cross-schema foreign key, and inheritance direction. It proves the required dependency parent is retained while a reverse parent-to-child relationship does not pull an unrelated child into the closure. No production query-algorithm change was needed for this configuration migration.Additional contracts cover mixed stock/scoped services, stock replacement equivalence, persistent gather cache behavior, unknown-service rejection, invalid dependency schemas, missing-type rejection, schema equality, and runtime execution.
Catalog benchmark
The scoped-only benchmark reuses the generic fresh-process runner/protocol/report. It uses a fixed 65-table root surface plus dependency and unrelated noise schemas, scalable catalog noise, identical explicit JIT settings, public gather-hook entity counts, and a separate query-only worker. Every arm used 10 fresh-process samples and all 240 worker PIDs were unique.
Environment: macOS arm64, Node v22.22.0, PostgreSQL 18.4 in a dedicated local container. PostgreSQL catalog cache is labeled
shared-server-not-reset; this is not a pristine-cache cold-start claim.JIT off (primary)
Negative percentages mean scoped reduced the metric.
At large scale, parsed classes fell from 64,220 to 270 and median heap fell from 839.6 MiB to 46.7 MiB. The small fixture shows why the feature remains opt-in.
JIT diagnostic
With JIT enabled, compilation dominates the recursive query at small/medium scale. The primary comparison therefore uses identical JIT-off sessions, matching CNC's scoped default. The benchmark reports the requested and observed JIT value for every run.
Stock/scoped schema hashes matched at every size and every runtime verification query passed:
d31e8b1c2d9cab3d1e67dcbc734e5addd237637028089221cf5f014b9ede4aa58c4e2e03008c98295978712461b799d23957ae89071326a16421ac4a7d0b199641c6ed8feb087766680ab1dc4d833e5082dbf69322b5fb2a118515e7c7ff9db0Reproduction
Fixture preparation never replaces or drops schemas. The large synthetic result demonstrates scale behavior; it is not a claim about typical production gains.
Validation
Passing:
graphile-scoped-introspection: 30 tests / 8 suites, including 6 real PostgreSQL dependency-closure casesgraphile-settingswiring/JIT contracts: 3 testspnpm install --frozen-lockfilegit diff --checkand PR-wide format-only diff auditNo database URL or password appears in benchmark JSON output.