Skip to content

perf(router): store subgraph operation text as a boxed str - #1535

Merged
kamilkisiela merged 4 commits into
kamil-qp-cache-pr3from
kamil-qp-cache-pr4
Sep 14, 2026
Merged

kamilkisiela merged 4 commits into
kamil-qp-cache-pr3from
kamil-qp-cache-pr4

Conversation

@kamilkisiela

Copy link
Copy Markdown
Contributor

No description provided.

@kamilkisiela
kamilkisiela added this pull request to stack #1534 September 10, 2026 11:45
@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

🐋 This PR was built and pushed to the following Docker images:

Image Names: ghcr.io/graphql-hive/router

Platforms: linux/amd64,linux/arm64

Image Tags: ghcr.io/graphql-hive/router:pr-1535 ghcr.io/graphql-hive/router:sha-99a495c

@kamilkisiela
kamilkisiela marked this pull request as ready for review September 10, 2026 13:55
@kamilkisiela
kamilkisiela marked this pull request as draft September 10, 2026 13:55
@kamilkisiela
kamilkisiela marked this pull request as ready for review September 10, 2026 16:22
`document_str` is rendered once when the plan is built and never appended to,
but a `String` keeps whatever capacity its doubling growth last landed on.
Measured over the bench plan's seven fetches, that is 1484 B allocated for 897 B
of text - 587 B, or 39.6%, held for the life of the cache entry to no purpose.

Box it. The struct field also drops the capacity word:

    SubgraphFetchOperation   40 -> 32 B
    FetchNode               216 -> 208 B
    BatchFetchNode          168 -> 160 B

`PlanNode` does not move. Two commits ago it would have: the fetch-carrying
variants were still inline then, so this 8 B would have come off every slot of
every `Sequence` and `Parallel`. Boxing those variants took that path away, and
what is left is 8 B per fetch rather than 8 B per node. The heap saving above is
per fetch either way, and is the larger half.

Nothing had to change to accommodate it beyond one `as_str()` call: the subgraph
request borrows the text and splices the operation name by position when it
builds the request body, so the text itself is never mutated in place.
@kamilkisiela
kamilkisiela merged commit 0f0d76a into main Sep 14, 2026
50 of 53 checks passed
@kamilkisiela
kamilkisiela deleted the kamil-qp-cache-pr4 branch September 14, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants