Skip to content

Add unit test for lastKeySearchHint inheritance in nested decoders#53

Merged
Joannis merged 3 commits intojo/key-lookup-optimizationsfrom
copilot/sub-pr-52
Jan 15, 2026
Merged

Add unit test for lastKeySearchHint inheritance in nested decoders#53
Joannis merged 3 commits intojo/key-lookup-optimizationsfrom
copilot/sub-pr-52

Conversation

Copy link
Contributor

Copilot AI commented Jan 15, 2026

Demonstrates potential optimization inefficiency where lastKeySearchHint is not reset when creating subDecoders, causing inherited hints to point to invalid offsets in child contexts.

Test Coverage

  • Simple nested objects: Parent with multiple sequential keys before nested object to establish hint value
  • Deep nesting (4 levels): Demonstrates compounding effect where each level inherits progressively invalid hints
  • Sequential key access: Triggers the hint mechanism to expose wraparound behavior

Behavior Verified

The test confirms current implementation handles nested objects correctly despite the issue. Wraparound logic in valueOffset(forKey:convertingSnakeCasing:in:hint:) prevents incorrect results but forces unnecessary wraparound searches when hints reference parent index space.

func subDecoder(offsetBy offset: Int) -> _JSONDecoder {
    let subDescription = self.description.unsafeReadOnlySubDescription(offset: offset)
    return _JSONDecoder(description: subDescription, codingPath: _codingPath, pointer: pointer, settings: settings)
    // lastKeySearchHint inherited here - points to parent's index space
}

Child decoders should initialize with lastKeySearchHint = Constants.firstArrayObjectChildOffset rather than inheriting parent's offset.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Joannis <1951674+Joannis@users.noreply.github.com>
@Joannis Joannis marked this pull request as ready for review January 15, 2026 10:52
Co-authored-by: Joannis <1951674+Joannis@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit test for object key lookup optimization Add unit test for lastKeySearchHint inheritance in nested decoders Jan 15, 2026
Copilot AI requested a review from Joannis January 15, 2026 10:55
@Joannis Joannis merged commit cc9867d into jo/key-lookup-optimizations Jan 15, 2026
3 checks passed
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