Replace O(n²) lookups with Map-based atoms in schema state layer - #1744
Merged
Merged
Conversation
- Add vertexPreferencesAtom and edgePreferencesAtom with .get(type) accessor that returns resolved preferences via O(1) Map lookup - Simplify vertexPreferenceByTypeAtom/edgePreferenceByTypeAtom to delegate to the new Map atoms - Simplify useAllVertexPreferences/useAllEdgePreferences by removing intermediate useStoredGraphPreferences wrapper - Pre-index vertex, edge, and preference arrays into Maps in mergeConfiguration, converting O(n²) .find() calls to O(1) lookups - Convert mergeAttributes to use Map-based lookups - Replace lodash cloneDeep with destructuring spread in patchToRemoveDisplayLabel, avoiding 70k deep clones - Replace lodash uniq() with native Set for deduplication - Fix circular import in storageAtoms.ts - Add tests for new atoms and patchToRemoveDisplayLabel immutability Part of aws#1678
kmcginnes
marked this pull request as ready for review
April 30, 2026 22:43
arseny-kostenko
approved these changes
Apr 30, 2026
5 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.
Description
Replace O(n²)
.find()loops with O(1) Map-based lookups across the schema state layer. At 70k vertex types,mergeConfigurationgoes from 18.8 seconds to 162 milliseconds (116x faster).vertexPreferencesAtomandedgePreferencesAtomwith.get(type)accessor that returns resolved preferences via O(1) Map lookup with default fallbackvertexPreferenceByTypeAtom/edgePreferenceByTypeAtomto delegate to the new Map atomsuseAllVertexPreferences/useAllEdgePreferencesby removing intermediateuseStoredGraphPreferenceswrappermergeConfiguration, converting O(n²).find()calls to O(1).get()lookupsmergeAttributesto use Map-based lookupslodash.cloneDeepwith destructuring spread inpatchToRemoveDisplayLabel, avoiding 70k deep cloneslodash.uniq()with nativeSetfor deduplicationstorageAtoms.tsBenchmarks (mergeConfiguration, 3 attributes per type)
Validation
patchToRemoveDisplayLabeldoes not mutate its inputRelated Issues
Check List
pnpm checkspasses with no errors.pnpm testpasses with no failures.