Skip to content

Use dictionary instead of switch statement - #16

Closed
erneestoc wants to merge 1 commit into
apollographql:mainfrom
erneestoc:erneestoc/schema-metadata-constant-access-type-lookup
Closed

erneestoc wants to merge 1 commit into
apollographql:mainfrom
erneestoc:erneestoc/schema-metadata-constant-access-type-lookup

Conversation

@erneestoc

Copy link
Copy Markdown

Why

  • Performance: Dictionary hash lookup is O(1) vs O(n) linear scan through switch cases. This function is called for every object in every GraphQL response during JSON deserialization.
  • Scales with schema size: The switch becomes increasingly expensive as schemas grow. Our production schema has ~4,200 types.
  • No behavioral change: The function signature, return type, and semantics are identical — returns the matching Object or nil.

@apollo-cla

Copy link
Copy Markdown

@erneestoc: 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/

@github-actions

Copy link
Copy Markdown
Contributor

We do not accept PRs directly to the 'apollo-ios-codegen' repo. All development is done through the 'apollo-ios-dev' repo, please see the CONTRIBUTING guide for more information.

@github-actions github-actions Bot closed this Mar 10, 2026
@erneestoc
erneestoc deleted the erneestoc/schema-metadata-constant-access-type-lookup branch March 25, 2026 06:10
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