Frontmatter
| id | 9076 |
| title | perf: Implement O(1) Lookup Map for internalId |
| state | Closed |
| labels | aiperformancecore |
| assignees | tobiu |
| createdAt | Feb 9, 2026, 2:46 PM |
| updatedAt | Feb 10, 2026, 2:09 AM |
| githubUrl | https://github.com/neomjs/neo/issues/9076 |
| author | tobiu |
| commentsCount | 2 |
| parentIssue | null |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Feb 10, 2026, 2:09 AM |
perf: Implement O(1) Lookup Map for internalId

Input from Gemini 3 Pro:
✦ Architecture & Implementation Plan (Handoff)
Objective: Restore O(1) performance for
internalIdlookups. Currently, the framework relies onstore.items.find(...)in critical paths (selection, navigation), which is O(N) and creates performance bottlenecks for large datasets.Architectural Decision: We will implement Option A: Direct Reference Map.
internalIdMapwill mapinternalId -> Item Reference(either a Record instance or a Raw Data Object).Implementation Plan:
Enhance
Neo.collection.Base:
- Add
trackInternalId: false(config).- Add
internalIdMap: null(property, initialized if tracking is enabled).- Add
getInternalKey(item)method (hook, default returns null).- Update
spliceandafterSetItemslogic to:
- Get the internal key via
getInternalKey(item).- If valid, add to
internalIdMap.- On remove, delete from
internalIdMap.- Add
getByInternalId(id)accessor method.Update
Neo.data.Store:
- Set
trackInternalId: trueby default.- Override
getInternalKey(item)to returnitem[internalId](using the symbol).- Turbo Mode Sync: In
get(key)andgetAt(index), when a Raw Object is hydrated into a Record:
- Explicitly update
internalIdMapto point to the new Record instance instead of the old Raw Object.- This ensures
getByInternalIdreturns the correct reference used by the View.Refactor Consumers (Cleanup Phase):
- Update
Helix,Gallery,ComboBox,GridBody,TableBody, andSelectionModels.- Replace all instances of
store.items.find(r => ... === id)withstore.getByInternalId(id).- This will dramatically simplify the record resolution logic and restore performance.
Note: The
internalIdsymbol is exported fromsrc/core/ConfigSymbols.mjs. Use it to access the property safely.

Input from Gemini 3 Pro:
✦ I have implemented the O(1)
internalIdMaplookup.Summary of Changes:
Core Framework (
Neo.collection.Base&Neo.data.Store):
- Implemented
internalIdMap(Map) inCollectionto track items byinternalId.- Added
trackInternalIdconfig (defaults tofalsein Collection,truein Store).- Updated
splice,filter,clear, anddestroyto maintain the map.- Enhanced
get(key)to automatically checkinternalIdMapif the key is not found in the primary map.- Updated
Storeto populateinternalIdMapwith Record instances upon hydration.Consumer Refactoring:
- Refactored
GridBody,TableBody,List,Gallery,Helix, andDragZoneto use the optimizedstore.get()method.- Removed all O(N) fallback iterations (e.g.,
store.items.find(...)) in Selection Models and Components.Verification:
- Created a new unit test:
test/playwright/unit/collection/InternalId.spec.mjs.- Verified
trackInternalIdtoggling, map population, record resolution, and cleanup on filter/splice/destroy.- All 8 tests passed.
The system now has O(1) performance for both Primary Key and Internal ID lookups.
Context: The recent adoption of
internalId(#9070) introduced robust identity for Records and Raw Objects. However, resolving an item from itsinternalIdcurrently relies onstore.items.find(...), which is an O(N) operation. In large datasets (e.g. 100k rows), this kills performance for selection, navigation, and drag-and-drop operations that rely on reverse lookup.Objective: Implement a secondary map (
internalIdMap) inNeo.collection.Baseto provide O(1) lookup forinternalId(or any secondary key).Architecture:
Collection.Base:
trackInternalIdconfig (or similar flag).internalIdMap(Map).getInternalKey(item)method (to be overridden).splice(add/remove logic) to maintaininternalIdMapin sync with the primary map.getByInternalId(id)accessor.Store:
getInternalKeyto returnitem[internalId].Refactor Consumers:
GridBody,TableBody,Helix,Gallery,SelectionModelsto usestore.getByInternalId(id)instead ofstore.items.find(...).Result: Restores O(1) performance for all ID-based lookups in the framework.