Skip to content

Conversation

@bryankeller
Copy link
Contributor

Details

This PR reduces calls to modelState.indexPathForItem(withID:) when calculating the yOffset for a targetContentOffsetAnchor. In most cases, like when scrolling and self-sizing cells, we already know the index path of the targetContentOffsetAnchor item - it's only when performing batch updates that we need to look up an index path using an ID (an O(n) search), since the index path might have changes as a result of batch updates.

Motivation and Context

Perf

@bryankeller bryankeller added the bug Something isn't working label Dec 3, 2025
case .topItem(let id, let _elementLocation, let distanceFromTop):
let elementLocation =
if isPerformingBatchUpdates {
modelState.indexPathForItemModel(withID: id).map(ElementLocation.init(indexPath:))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the O(n) call we can avoid as long as we're not performing batch updates

brynbodayle
brynbodayle previously approved these changes Dec 3, 2025
Copy link
Contributor

@brynbodayle brynbodayle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@bryankeller bryankeller merged commit 3ee1ad2 into master Dec 4, 2025
1 check passed
@bryankeller bryankeller deleted the bk/reduce-index-path-lookups branch December 4, 2025 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants