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

fix short circuiting logic when doing exact matches #32

Merged
merged 3 commits into from
Dec 17, 2023
Merged

fix short circuiting logic when doing exact matches #32

merged 3 commits into from
Dec 17, 2023

Conversation

noib3
Copy link
Contributor

@noib3 noib3 commented Nov 24, 2023

I noticed you stop looking for matches as soon as score >= self.config.bonus_boundary_white. I believe this is a typo since score is always >= 16 and bonus_boundary_white is always <= 10, which means you always return the score (and position) of the first match.

This is done in a bunch of place in the exact module. I've only fixed the first one because I wanted to get some feedback before fixing the others. If it LGTY I can go ahead.

@noib3 noib3 marked this pull request as draft November 24, 2023 20:08
@noib3 noib3 changed the title draft: fix short circuiting logic when doing exact matches fix short circuiting logic when doing exact matches Nov 24, 2023
@noib3 noib3 marked this pull request as ready for review November 24, 2023 20:09
@pascalkuthe
Copy link
Member

I think while you do have found a bug here the fix is not quite right.

The condition should be bonus >= self.config.bonus_boundary_white (which is the maximum possible bonus and in turn the maximum possible score for a single char match).

So you only need to change if score >= self.config.bonus_boundary_white { to if bonus >= self.config.bonus_boundary_white { (which is indeed a typeo)

@noib3
Copy link
Contributor Author

noib3 commented Nov 24, 2023

@pascalkuthe yes, but then you're recalculating the score every time there's a match, which you don't need to. The latest commit only computes it once at the end, when the best bonus is known.

@pascalkuthe
Copy link
Member

pascalkuthe commented Nov 24, 2023

ah I see now, I didn't fully get that on first scan. I would have relied on the compiler to optimize that. That mostly looks like a textbook case for LICM but I guess why not.

@noib3
Copy link
Contributor Author

noib3 commented Nov 25, 2023

@pascalkuthe I've fixed the other functions, added a couple of tests and updated the CHANGELOG.

That mostly looks like a textbook case for LICM but I guess why not.

I've benchmarked recomputing the score on every match vs once at the end, and I think you're right. There's no difference. The latest commit does the latter but I can change it to how it was originally if you prefer that. Edit: now doing the former for consistency and ease of review.

@noib3
Copy link
Contributor Author

noib3 commented Nov 29, 2023

Is there something left to do here?

@pascalkuthe
Copy link
Member

sorry for the delay this got a bit lost in my endless stream of notificatons

@pascalkuthe pascalkuthe merged commit b41c989 into helix-editor:master Dec 17, 2023
5 checks passed
@noib3 noib3 deleted the fix-single-char-needles branch December 17, 2023 16:28
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