Skip to content

Use dictionary instead of switch for objectType(forTypename:) lookup#918

Merged
AnthonyMDev merged 4 commits intomainfrom
claude/fix-apollo-performance-Pr8r8
Mar 20, 2026
Merged

Use dictionary instead of switch for objectType(forTypename:) lookup#918
AnthonyMDev merged 4 commits intomainfrom
claude/fix-apollo-performance-Pr8r8

Conversation

@AnthonyMDev
Copy link
Copy Markdown
Contributor

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

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
@apollo-librarian
Copy link
Copy Markdown

apollo-librarian Bot commented Mar 19, 2026

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 5595c1151f492eccf79c777a
Build Logs: View logs


✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 19, 2026

Deploy Preview for apollo-ios-docc canceled.

Name Link
🔨 Latest commit d774fb0
🔍 Latest deploy log https://app.netlify.com/projects/apollo-ios-docc/deploys/69bd7f56c7c8fa0009a89ee7

@AnthonyMDev AnthonyMDev requested a review from BobaFetters March 20, 2026 16:56
@AnthonyMDev AnthonyMDev merged commit 27d54a9 into main Mar 20, 2026
21 checks passed
@AnthonyMDev AnthonyMDev deleted the claude/fix-apollo-performance-Pr8r8 branch March 20, 2026 21:45
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>
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