Repository: microsoft/PowerToys
File: src/modules/peek/Peek.FilePreviewer/Previewers/UnsupportedFilePreviewer/UnsupportedFilePreviewer.cs (C#)

Code before:
                DefaultIcon;
        }

        private async Task LoadDisplayInfoAsync(IProgress<string> sizeProgress, CancellationToken cancellationToken)
        {
            string type = await Item.GetContentTypeAsync();

            Dispatcher.TryEnqueue(() => Preview.FileType = type);

            if (Item is FolderItem folderItem)
            {
                await Task.Run(() => CalculateFolderSizeWithProgress(Item.Path, sizeProgress, cancellationToken), cancellationToken);
            }
            else
            {
                ReportProgress(sizeProgress, Item.FileSizeBytes);
            }
        }

        private void CalculateFolderSizeWithProgress(string path, IProgress<string> progress, CancellationToken cancellationToken)
        {
            ulong folderSize = 0;
            TimeSpan updateInterval = TimeSpan.FromMilliseconds(1000 / MaxUpdateFps);
            DateTime nextUpdate = DateTime.UtcNow + updateInterval;

            var files = new DirectoryInfo(path).EnumerateFiles("*", new EnumerationOptions { RecurseSubdirectories = true });

            foreach (var chunk in files.Chunk(FolderEnumerationChunkSize))
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (DateTime.Now >= nextUpdate)
                {
                    ReportProgress(progress, folderSize);
                    nextUpdate = DateTime.UtcNow + updateInterval;
                }

                foreach (var file in chunk)
                {
                    folderSize += (ulong)file.Length;
                }
            }

            ReportProgress(progress, folderSize);
        }

        private void ReportProgress(IProgress<string> progress, ulong size)
        {
            progress.Report(ReadableStringHelper.BytesToReadableString(size));
        }
    }

Review comment (suggestion):
Let's move `new EnumerationOptions { RecurseSubdirectories = true }` in a static field to reuse it across multiple previews, although I don't think the overhead will be that high.

Code after:
            {
                var storageItem = await Item.GetStorageItemAsync();
                ClipboardHelper.SaveToClipboard(storageItem);
            });
        }

        private async Task LoadIconPreviewAsync(CancellationToken cancellationToken)
        {
            Preview.IconPreview = await ThumbnailHelper.GetThumbnailAsync(Item.Path, cancellationToken) ??
                await ThumbnailHelper.GetIconAsync(Item.Path, cancellationToken) ??
                DefaultIcon;
        }

        private async Task LoadDisplayInfoAsync(IProgress<string> sizeProgress, CancellationToken cancellationToken)
        {
            string type = await Item.GetContentTypeAsync();

            Dispatcher.TryEnqueue(() => Preview.FileType = type);

            if (Item is FolderItem folderItem)
            {
                await Task.Run(() => CalculateFolderSizeWithProgress(Item.Path, sizeProgress, cancellationToken), cancellationToken);
            }
            else
            {
                ReportProgress(sizeProgress, Item.FileSizeBytes);
            }
        }

        private void CalculateFolderSizeWithProgress(string path, IProgress<string> progress, CancellationToken cancellationToken)
        {
            ulong folderSize = 0;
            TimeSpan updateInterval = TimeSpan.FromMilliseconds(1000 / MaxUpdateFps);
            DateTime nextUpdate = DateTime.UtcNow + updateInterval;

            var files = new DirectoryInfo(path).EnumerateFiles("*", FolderEnumerationOptions);

            foreach (var chunk in files.Chunk(FolderEnumerationChunkSize))
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (DateTime.Now >= nextUpdate)
                {
                    ReportProgress(progress, folderSize);
                    nextUpdate = DateTime.UtcNow + updateInterval;
                }

                foreach (var file in chunk)
                {
                    folderSize += (ulong)file.Length;
                }