Use dictionary instead of switch for objectType(forTypename:) lookup#918
Merged
AnthonyMDev merged 4 commits intomainfrom Mar 20, 2026
Merged
Use dictionary instead of switch for objectType(forTypename:) lookup#918AnthonyMDev merged 4 commits intomainfrom
AnthonyMDev merged 4 commits intomainfrom
Conversation
Replace the generated switch statement in SchemaMetadata.objectType(forTypename:) with a static dictionary lookup. For schemas with many object types (4000+), the switch statement performs a linear O(n) scan on each call, while the dictionary provides O(1) hash-based lookup after one-time initialization. This addresses apollographql/apollo-ios#3631 where users with large schemas (~4300 types) reported ~200ms deserialization times that improved ~75% with a dictionary approach. Changes: - Update SchemaMetadataTemplate to generate a private static objectTypeMap dictionary instead of a switch statement - Update all generated SchemaMetadata.graphql.swift files to match - Update SchemaMetadataTemplateTests for new output format - Add ObjectTypeLookupPerformanceTests comparing both approaches https://claude.ai/code/session_01UiBwk4UkoHpdB1hNSuZ665
✅ Docs preview has no changesThe preview was not built because there were no changes. Build ID: 5595c1151f492eccf79c777a ✅ AI Style Review — No Changes DetectedNo MDX files were changed in this pull request. Review Log: View detailed log
|
✅ Deploy Preview for apollo-ios-docc canceled.
|
BobaFetters
pushed a commit
that referenced
this pull request
Mar 20, 2026
BobaFetters
pushed a commit
that referenced
this pull request
Mar 20, 2026
…h for objectType(forTypename:) lookup git-subtree-dir: apollo-ios-codegen git-subtree-mainline: b24d16a git-subtree-split: daa8849ddc7cf67ad3d038b0ecf8e98742b4501c
AnthonyMDev
added a commit
that referenced
this pull request
Mar 25, 2026
Backport of #918 from main. Replace the generated switch statement in SchemaMetadata.objectType(forTypename:) with a static dictionary lookup. For schemas with many object types (4000+), the switch statement performs a linear O(n) scan on each call, while the dictionary provides O(1) hash-based lookup after one-time initialization. This addresses apollographql/apollo-ios#3631 where users with large schemas (~4300 types) reported ~200ms deserialization times that improved ~75% with a dictionary approach. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
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.
Replace the generated switch statement in SchemaMetadata.objectType(forTypename:) with a static dictionary lookup. For schemas with many object types (4000+), the switch statement performs a linear O(n) scan on each call, while the dictionary provides O(1) hash-based lookup after one-time initialization.
This addresses apollographql/apollo-ios#3631 where users with large schemas (~4300 types) reported ~200ms deserialization times that improved ~75% with a dictionary approach.
Changes:
https://claude.ai/code/session_01UiBwk4UkoHpdB1hNSuZ665