PrefixContainer.GetKeysFromPrefix does a full linear scan instead of using the existing sorted array
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
`PrefixContainer` already builds a sorted copy of all form keys in the constructor (used by `ContainsPrefix` via binary search), but `GetKeysFromPrefix` ignores it and iterates `_originalValues` linearly every time it's called. In case of nested collection models with inner `Dictionary<>` call is repeated, so should be optimized.
The fix would be to use `_sortedValues` in `GetKeysFromPrefix` — binary search to find the start of the prefix range, then scan forward only while entries still match, reducing each call from O(N) to O(log N + M) where M is the number of matching entries.
Contributor guide
Research direction
Start at PrefixContainer.GetKeysFromPrefix and compare its current iteration with ContainsPrefix, which already uses the sorted values and binary search. Trace _sortedValues and _originalValues to confirm the prefix-range behavior; done means matching keys are returned with existing behavior while the lookup uses the sorted range rather than a full scan.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100