Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fragment support #562

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

igor-florescu-ck
Copy link

@igor-florescu-ck igor-florescu-ck commented Dec 29, 2024

We are currently migrating to the new Apollo codegen.

The new codegen tool runs for over 30 minutes and uses a lot of memory to generate the latest Swift types, and our CI is failing to complete. I suspect this thread might be related to apollographql/apollo-ios#3434.

I am opening this pull request to propose changes and gather feedback from the repo authors.

What is happening?
Whenever the RootFieldBuilder builds named fragments via buildNamedFragmentSpread. The codegen flow will eventually reuse a previously built fragment from BuiltFragmentStorage. Once resolved, a NamedFragment type would be returned by the codegen flow and will use the Entity fields to build up the EntitySelectionTree in the Selection Set which references the fragment.

The fragments resolved from BuiltFragmentStorage are eventually referenced to it's previously created swift file.

Some fragments can contain very large amounts of Entity fields which might not be relevant for referencing intents.

With this pull request, I propose adding support for partial NamedFragment to reduce the amount of data merged into the EntitySelectionTree.

The intention of partial fragments is to return a NamedFragment which contain entities necessary for referencing intents. (ex: field for inlineFragments, references for referencedFragments etc.)

In this example, I am reducing the number of entities filtered out that have FieldPaths deeper than 3 (?)

What is outcome?
With this change, the same swift output is generated according to our schema, but the duration is reduced from 30 minutes to 3 minutes, and memory usage has decreased to 400 MB.

Copy link

netlify bot commented Dec 29, 2024

👷 Deploy request for eclectic-pie-88a2ba pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 2c49f9c

Copy link

netlify bot commented Dec 29, 2024

👷 Deploy request for apollo-ios-docc pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 2c49f9c

@apollo-cla
Copy link

@igor-florescu-ck: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Dec 29, 2024

✅ Docs Preview Ready

No new or changed pages found.

@igor-florescu-ck igor-florescu-ck changed the title [3434][Perf]: Partial fragment support Partial fragment support Dec 29, 2024
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.

3 participants