Program Plugin: Avoid Slow IShellLink::Resolve Search When Reading Shortcuts
Split out of #4741 as requested there. This PR changes only ShellLinkReader.cs. It is independent of #4741 (no shared files) and combines with it.
Problem
Every Win32 index reads each Start Menu shortcut with IShellLink::Resolve(SLR_NO_UI). Resolve searches for missing targets (link tracking and volume lookups, with the default 3 s timeout per link). On a machine with 801 shortcuts, 53 of them with a missing target:
| Reading 801 shortcuts | Total | Worst link |
|---|---|---|
Resolve(SLR_NO_UI) (current) | 109 s | 3 s |
Resolve(NO_UI | NOUPDATE | NOSEARCH | NOTRACK | NOLINKINFO) | 0.9 s | 13 ms |
Of the 53 broken shortcuts, the full 3 s search repaired exactly 1, and that one was repaired in 7 ms. A 50 ms timeout repairs the same set.
Change
- Resolve with
SLR_NOUPDATE | SLR_NOSEARCH | SLR_NOTRACK | SLR_NOLINKINFO. - If the target is still missing (or the fast
Resolvefails): a secondResolve(SLR_NO_UI)with a 50 ms timeout (high word of the flags). Only aLoadfailure returns early. - The repair only updates the in-memory link object. The
.lnkfile is never written (the current code doesn't persist repairs either).
Results (Release build of v2.1.4 with only this change, same machine)
| Before | After | |
|---|---|---|
| Full Win32 index | 113.7 s | 6.0 s (at startup) |
| Reindex after a Start Menu change (each one is a full index without #4741) | ~114 s | ~4.7 s (~3.4 s CPU) |
The review feedback from #4741 about this file (failed fast Resolve must still reach the repair; the comment about saving the repair) is included.
Summary by cubic
Summary of changes
Speeds up Win32 shortcut reading by ~100x by avoiding the slow IShellLink::Resolve search for missing targets.
- Changed: shortcuts are now resolved with
SLR_NOUPDATE | SLR_NOSEARCH | SLR_NOTRACK | SLR_NOLINKINFOinstead ofSLR_NO_UIalone, skipping the 3-second-per-link target search. - Added: when the target is still missing or the fast
Resolvethrows, a secondResolvecapped at 50ms attempts a repair; measured to repair the same links as the 3s default. - Removed: the early return on fast
Resolvefailure; a failed fast resolve now falls through to the repair attempt. - The repair only updates the in-memory link object; the
.lnkfile is never written. - No memory usage impact and no new security risks.
- No unit tests were added for this change.
Release Note
Shortcuts with missing targets are now read much faster without losing the ability to repair them, making Start Menu indexing noticeably quicker.