Skip to content

[CmdPal] Fix slow fuzzy search in apps extension by properly handling null-terminated strings from SHLoadIndirectString #40198

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

Merged
merged 2 commits into from
Jun 24, 2025

Conversation

lei9444
Copy link
Contributor

@lei9444 lei9444 commented Jun 23, 2025

Summary of the Pull Request

This change addresses a significant performance regression caused by improper handling of null-terminated strings returned from the SHLoadIndirectString API.

Previously, the output buffer was converted to string using Span.ToString() without trimming at the null terminator (\0). As a result, the entire buffer (1024 characters) was converted, including trailing garbage data after the valid string.

This caused the fuzzy matching logic to process unnecessarily long strings, leading to excessive CPU usage and input lag (~2 seconds delay per keystroke).

The fix properly locates the first null terminator in the buffer and slices the span before converting to string, eliminating trailing garbage characters. This reduces the workload in the scoring function and resolves the input lag in the apps extension search.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@lei9444 lei9444 added this to the PowerToys 0.92 milestone Jun 23, 2025
@michaeljolley michaeljolley added the Product-Command Palette Refers to the Command Palette utility label Jun 23, 2025
Copy link
Contributor

@vanzue vanzue left a comment

Choose a reason for hiding this comment

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

looks good

Copy link
Contributor

@yeelam-gordon yeelam-gordon left a comment

Choose a reason for hiding this comment

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

Please see my minor comments, but it may helps on diagnostic.

@lei9444 lei9444 merged commit 0c870d6 into main Jun 24, 2025
14 checks passed
yeelam-gordon pushed a commit that referenced this pull request Jun 27, 2025
… null-terminated strings from SHLoadIndirectString (#40198)

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
This change addresses a significant performance regression caused by
improper handling of null-terminated strings returned from the
SHLoadIndirectString API.

Previously, the output buffer was converted to string using
Span<char>.ToString() without trimming at the null terminator (\0). As a
result, the entire buffer (1024 characters) was converted, including
trailing garbage data after the valid string.

This caused the fuzzy matching logic to process unnecessarily long
strings, leading to excessive CPU usage and input lag (~2 seconds delay
per keystroke).

The fix properly locates the first null terminator in the buffer and
slices the span before converting to string, eliminating trailing
garbage characters. This reduces the workload in the scoring function
and resolves the input lag in the apps extension search.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] **Closes:** #40197
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Product-Command Palette Refers to the Command Palette utility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants