Repository: microsoft/PowerToys
File: src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs (C#)

Code before:

            // If the new string doesn't start with the old string, then we can't
            // re-use previous results. Reset _filteredItems, and keep er moving.
            if (!newSearch.StartsWith(oldSearch, StringComparison.CurrentCultureIgnoreCase))
            {
                _filteredItems = null;
            }

            // If the internal state has changed, reset _filteredItems to reset the list.
            if (_filteredItemsIncludesApps != _includeApps)
            {
                _filteredItems = null;
            }

            // If we don't have any previous filter results to work with, start
            // with a list of all our commands & apps.
            if (_filteredItems == null)
            {
                _filteredItems = commands;
                _filteredItemsIncludesApps = _includeApps;
                if (_includeApps)
                {
                    IEnumerable<IListItem> apps = AllAppsCommandProvider.Page.GetItems();

                    // Remove any top level pinned apps and use the apps from AllAppsCommandProvider.Page.GetItems()
                    _filteredItems = _filteredItems.Where(item =>
                                                        item is not TopLevelViewModel topLevelViewModel ||
                                                        !apps.Any(app => app.Command.Id == topLevelViewModel.Id));

                    _filteredItems = _filteredItems.Concat(apps);
                }
            }

            // Produce a list of everything that matches the current filter.
            _filteredItems = ListHelpers.FilterList<IListItem>(_filteredItems, SearchText, ScoreTopLevelItem);
            RaiseItemsChanged(_filteredItems.Count());
        }
    }

    private void UpdateFallbacks(string newSearch, IReadOnlyList<TopLevelViewModel> commands)
    {
        // fire and forget
        _ = Task.Run(() =>
        {
            var needsToUpdate = false;

            foreach (var command in commands)
            {
                var changedVisibility = command.SafeUpdateFallbackTextSynchronous(newSearch);
                needsToUpdate = needsToUpdate || changedVisibility;
            }

Review comment (suggestion):
Could we save some CPU cycles by just checking 

```cs
_filteredItems = _filteredItems.Where(item => item is not AppListItem);
```

having to iterate over all the apps for every item sounds long

Code after:

            // If the new string doesn't start with the old string, then we can't
            // re-use previous results. Reset _filteredItems, and keep er moving.
            if (!newSearch.StartsWith(oldSearch, StringComparison.CurrentCultureIgnoreCase))
            {
                _filteredItems = null;
            }

            // If the internal state has changed, reset _filteredItems to reset the list.
            if (_filteredItemsIncludesApps != _includeApps)
            {
                _filteredItems = null;
            }

            // If we don't have any previous filter results to work with, start
            // with a list of all our commands & apps.
            if (_filteredItems == null)
            {
                _filteredItems = commands;
                _filteredItemsIncludesApps = _includeApps;
                if (_includeApps)
                {
                    IEnumerable<IListItem> apps = AllAppsCommandProvider.Page.GetItems();
                    var appIds = apps.Select(app => app.Command.Id).ToArray();

                    // Remove any top level pinned apps and use the apps from AllAppsCommandProvider.Page.GetItems()
                    // since they contain details.
                    _filteredItems = _filteredItems.Where(item => item.Command is not AppCommand);
                    _filteredItems = _filteredItems.Concat(apps);
                }
            }

            // Produce a list of everything that matches the current filter.
            _filteredItems = ListHelpers.FilterList<IListItem>(_filteredItems, SearchText, ScoreTopLevelItem);
            RaiseItemsChanged(_filteredItems.Count());
        }
    }

    private void UpdateFallbacks(string newSearch, IReadOnlyList<TopLevelViewModel> commands)
    {
        // fire and forget
        _ = Task.Run(() =>
        {
            var needsToUpdate = false;

            foreach (var command in commands)
            {
                var changedVisibility = command.SafeUpdateFallbackTextSynchronous(newSearch);
                needsToUpdate = needsToUpdate || changedVisibility;
            }