Program Plugin: Avoid Slow IShellLink::Resolve Search When Reading Shortcuts

Merged
UN
18d ago
+32-5

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 shortcutsTotalWorst link
Resolve(SLR_NO_UI) (current)109 s3 s
Resolve(NO_UI | NOUPDATE | NOSEARCH | NOTRACK | NOLINKINFO)0.9 s13 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 Resolve fails): a second Resolve(SLR_NO_UI) with a 50 ms timeout (high word of the flags). Only a Load failure returns early.
  • The repair only updates the in-memory link object. The .lnk file is never written (the current code doesn't persist repairs either).

Results (Release build of v2.1.4 with only this change, same machine)

BeforeAfter
Full Win32 index113.7 s6.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_NOLINKINFO instead of SLR_NO_UI alone, skipping the 3-second-per-link target search.
  • Added: when the target is still missing or the fast Resolve throws, a second Resolve capped at 50ms attempts a repair; measured to repair the same links as the 3s default.
  • Removed: the early return on fast Resolve failure; a failed fast resolve now falls through to the repair attempt.
  • The repair only updates the in-memory link object; the .lnk file 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.