feat: optimisation of EqualMatch method#3342
feat: optimisation of EqualMatch method#3342Sanix-Darker wants to merge 2 commits intojunegunn:masterfrom
Conversation
- Combined whitespace stripping: The leading and trailing whitespaces are stripped in a single step, reducing the number of method calls and condition checks.
- Reduced string conversions: Instead of converting the entire text and pattern to strings, only the necessary substrings are used. This avoids unnecessary conversions and improves performance.
- Early return: The function returns early if the normalized characters or string comparison fails, eliminating the need for the match boolean variable and reducing unnecessary computations.
|
Hello, I didn't create an issue for this PR, sorry for that, do you want me to provide more details with benchmarks ? @junegunn |
No problem with that.
That would be nice, yes. But if the suggested change is succinct and it makes the code objectively better, then we can merge it even if it doesn't bring a significant performance boost. Just out of curiosity, can you tell me why you started looking into improving EqualMatch? which is 1. rarely used (only triggered when you type in |
I am a GIGA big fan and a daily user of fzf, so I was wondering how it works, I started reading the code and I wanted to provide my optimization "point of view" on some methods for this module, but in multiple small and different PRs, that's why I started with the smallest and easiest one
You're right for that, I will be glad to work on other "most important perfs issues" from your experience if you have some to provide me ! |
PROPOSAL
Testing some optimisations i wanted to check :
Combined whitespace stripping: The leading and trailing whitespaces are stripped in a single step, reducing the number of method calls and condition checks.
Reduced string conversions: Instead of converting the entire text and pattern to strings, only the necessary substrings are used. This avoids unnecessary conversions and improves performance.
Early return: The function returns early if the normalized characters or string comparison fails, eliminating the need for the match boolean variable and reducing unnecessary computations.