Skip to content

[5.10] [Source manager] Improve the performance of findBufferContainingLocInternal #68980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

DougGregor
Copy link
Member

This function was performing a linear scan through the set of known buffers to find the buffer containing a given source location. This linear scan can show up in hot loops, and the number of buffers in a program is increasing due to macros, so this has become a performance problem.

Replace the linear scan with a logarithmic lookup into a sorted vector of the buffer IDs, with a one-element most-recently-used cache so that repeated lookups in the same buffer require constant time.

This mirrors what we already do with source files in a module. Unfortunately, we cannot reuse that code because there is no link from buffers to source files. We should look to consolidate this in the future.

Fixes rdar://116184248.

Original PR: #68971

…ternal()

This function was performing a linear scan through the set of known
buffers to find the buffer containing a given source location. This
linear scan can show up in hot loops, and the number of buffers in a
program is increasing due to macros, so this has become a performance
problem.

Replace the linear scan with a logarithmic lookup into a sorted vector
of the buffer IDs, with a one-element most-recently-used cache so that
repeated lookups in the same buffer require constant time.

This mirrors what we already do with source files in a module.
Unfortunately, we cannot reuse that code because there is no link from
buffers to source files. We should look to consolidate this in the
future.

Fixes rdar://116184248.
@DougGregor DougGregor requested a review from a team as a code owner October 5, 2023 12:15
@DougGregor
Copy link
Member Author

@swift-ci please test

3 similar comments
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit 7a3aa36 into swiftlang:release/5.10 Oct 6, 2023
@DougGregor DougGregor deleted the faster-find-buffer-containing-loc-5.10 branch October 6, 2023 03:59
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