Skip to content

Use dictionary instead of switch statement#16

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

Use dictionary instead of switch statement#16
erneestoc wants to merge 1 commit intoapollographql:mainfrom
erneestoc:erneestoc/schema-metadata-constant-access-type-lookup

Conversation

@erneestoc
Copy link

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

@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
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.

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