Skip to content
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

contentprovider: cache last newlines lookup #722

Closed
wants to merge 1 commit into from
Closed

Conversation

keegancsmith
Copy link
Member

I wanted to introduce another call to newlines.atOffset for the purpose of scoring. I was worried about doubling the calls to this so introduced a tiny (but hopefully effective) performance optimization.

Essentially we often look up multiple times on the same line, but then the return of atOffset shouldn't change. So we introduce a tiny cache for this.

We could do even more and if we are not on the same line, use the last computed index to restrict which side of the nls.locs we look at. However, there are no direct benchmarks for this and I haven't seen it in profiles before. So just doing this minor optimization for fun.

Test Plan: go test

I wanted to introduce another call to newlines.atOffset for the purpose
of scoring. I was worried about doubling the calls to this so introduced
a tiny (but hopefully effective) performance optimization.

Essentially we often look up multiple times on the same line, but then
the return of atOffset shouldn't change. So we introduce a tiny cache
for this.

We could do even more and if we are not on the same line, use the last
computed index to restrict which side of the nls.locs we look at.
However, there are no direct benchmarks for this and I haven't seen it
in profiles before. So just doing this minor optimization for fun.

Test Plan: go test
@keegancsmith
Copy link
Member Author

Alright turns out I don't need this. I am gonna close this out, since unless I see this appearing in a profile it isn't worth the extra complexity.

@keegancsmith keegancsmith deleted the k/newlines branch January 22, 2024 09:24
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.

1 participant