Repository: files-community/Files
File: src/Files.App/Views/Layouts/BaseLayoutPage.cs (C#)

Code before:
				if (sendToMenuItem?.LoadSubMenuAction is not null && sendToOverflow is not null && sendTo is not null)
				{
					await sendToMenuItem.LoadSubMenuAction();
					var sendToSubItems = ContextFlyoutModelToElementHelper.GetMenuFlyoutItemsFromModel(ShellContextFlyoutFactory.GetSendToItems(shellMenuItems));

					if (sendToSubItems is not null)
					{
						var flyout = (MenuFlyout)sendToOverflow.Flyout;

						flyout.Items.Clear();

						foreach (var item in sendToSubItems)
							flyout.Items.Add(item);

						sendToOverflow.Flyout = flyout;
						sendTo.Visibility = Visibility.Collapsed;
						sendToOverflow.Visibility = Visibility.Visible;
					}
				}
			}

			// Filter mainShellMenuItems that have a non-null LoadSubMenuAction
			var mainItemsWithSubMenu = mainShellMenuItems.Where(x => x.LoadSubMenuAction is not null);

			// Load main submenus asynchronously
			await Task.WhenAll(mainItemsWithSubMenu.Select(async item =>
			{
				await item.LoadSubMenuAction();
				ShellContextFlyoutFactory.AddItemsToMainMenu(mainItems, item);
			}));
			
			// Filter overflowShellMenuItems that have a non-null LoadSubMenuAction
			var overflowItemsWithSubMenu = overflowShellMenuItems.Where(x => x.LoadSubMenuAction is not null).ToList();
			
			var subMenuTasks = overflowItemsWithSubMenu.Select(async item =>
			{
				await item.LoadSubMenuAction();
				ShellContextFlyoutFactory.AddItemsToOverflowMenu(overflowItem, item);
			});

			await Task.WhenAll(subMenuTasks);

			itemsControl?.Items.OfType<FrameworkElement>().ForEach(item =>
			{
				// Enable CharacterEllipsis text trimming for menu items
				if (item.FindDescendant("OverflowTextLabel") is TextBlock label)
					label.TextTrimming = TextTrimming.CharacterEllipsis;

				// Close main menu when clicking on subitems (#5508)
				if ((item as AppBarButton)?.Flyout as MenuFlyout is MenuFlyout flyout)
				{

Review comment (bug):
I think `mainItemsWithSubMenu.Select` tasks and `overflowItemsWithSubMenu.Select` tasks can be grouped together and await in one `Task.WhenAll`.

Code after:
				if (sendToMenuItem?.LoadSubMenuAction is not null && sendToOverflow is not null && sendTo is not null)
				{
					await sendToMenuItem.LoadSubMenuAction();
					var sendToSubItems = ContextFlyoutModelToElementHelper.GetMenuFlyoutItemsFromModel(ShellContextFlyoutFactory.GetSendToItems(shellMenuItems));

					if (sendToSubItems is not null)
					{
						var flyout = (MenuFlyout)sendToOverflow.Flyout;

						flyout.Items.Clear();

						foreach (var item in sendToSubItems)
							flyout.Items.Add(item);

						sendToOverflow.Flyout = flyout;
						sendTo.Visibility = Visibility.Collapsed;
						sendToOverflow.Visibility = Visibility.Visible;
					}
				}
			}

			// Filter mainShellMenuItems that have a non-null LoadSubMenuAction
			var mainItemsWithSubMenu = mainShellMenuItems.Where(x => x.LoadSubMenuAction is not null);
			
			var mainSubMenuTasks = mainItemsWithSubMenu.Select(async item =>
			{
				await item.LoadSubMenuAction();
				ShellContextFlyoutFactory.AddItemsToMainMenu(mainItems, item);
			});

			// Filter overflowShellMenuItems that have a non-null LoadSubMenuAction
			var overflowItemsWithSubMenu = overflowShellMenuItems.Where(x => x.LoadSubMenuAction is not null);

			var overflowSubMenuTasks = overflowItemsWithSubMenu.Select(async item =>
			{
				await item.LoadSubMenuAction();
				ShellContextFlyoutFactory.AddItemsToOverflowMenu(overflowItem, item);
			});
			
			itemsControl?.Items.OfType<FrameworkElement>().ForEach(item =>
			{
				// Enable CharacterEllipsis text trimming for menu items
				if (item.FindDescendant("OverflowTextLabel") is TextBlock label)
					label.TextTrimming = TextTrimming.CharacterEllipsis;

				// Close main menu when clicking on subitems (#5508)
				if ((item as AppBarButton)?.Flyout as MenuFlyout is MenuFlyout flyout)
				{
					Action<IList<MenuFlyoutItemBase>> clickAction = null!;
					clickAction = (items) =>
					{