-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Main Goal Improve FileCleanup logics for items > 1000 as before it froze the UI completely 1. Use SelectAllSafe and UnselectAll to do as described > Improved speed when selecting all items by (from ~140000 ms to ~170ms) when selecting 25000 files. 2. Use .NET's built-in SIMD calculation for summing all the asset sizes 3. Use batching when injecting files to the ListViewTable source ## PR Status : - Overall Status : Done - Commits : Done - Synced to base (Collapse:main) : Yes - Build status : OK - Crashing : No - Bug found caused by PR : 0 Co-authored-by: Kemal Setya Adhi <[email protected]>
- Loading branch information
Showing
11 changed files
with
517 additions
and
191 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
CollapseLauncher/Classes/Extension/ObservableCollectionExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Collections.Specialized; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace CollapseLauncher.Extension | ||
{ | ||
/// <summary> | ||
/// Provides extension methods for <see cref="ObservableCollection{T}"/>. | ||
/// </summary> | ||
/// <typeparam name="T">The type of elements in the collection.</typeparam> | ||
internal static class ObservableCollectionExtension<T> | ||
{ | ||
/// <summary> | ||
/// Gets the backing list of the specified collection. | ||
/// </summary> | ||
/// <param name="source">The collection to get the backing list from.</param> | ||
/// <returns>A reference to the backing list of the collection.</returns> | ||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "items")] | ||
internal static extern ref IList<T> GetBackedCollectionList(Collection<T> source); | ||
|
||
/// <summary> | ||
/// Invokes the OnCountPropertyChanged method on the specified observable collection. | ||
/// </summary> | ||
/// <param name="source">The observable collection to invoke the method on.</param> | ||
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = "OnCountPropertyChanged")] | ||
internal static extern void OnCountPropertyChanged(ObservableCollection<T> source); | ||
|
||
/// <summary> | ||
/// Invokes the OnIndexerPropertyChanged method on the specified observable collection. | ||
/// </summary> | ||
/// <param name="source">The observable collection to invoke the method on.</param> | ||
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = "OnIndexerPropertyChanged")] | ||
internal static extern void OnIndexerPropertyChanged(ObservableCollection<T> source); | ||
|
||
/// <summary> | ||
/// Invokes the OnCollectionChanged method on the specified observable collection. | ||
/// </summary> | ||
/// <param name="source">The observable collection to invoke the method on.</param> | ||
/// <param name="e">The event arguments for the collection changed event.</param> | ||
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = "OnCollectionChanged")] | ||
internal static extern void OnCollectionChanged(ObservableCollection<T> source, NotifyCollectionChangedEventArgs e); | ||
|
||
/// <summary> | ||
/// Refreshes all events for the specified observable collection. | ||
/// </summary> | ||
/// <param name="source">The observable collection to invoke the method on.</param> | ||
internal static void RefreshAllEvents(ObservableCollection<T> source) | ||
{ | ||
OnCountPropertyChanged(source); | ||
OnIndexerPropertyChanged(source); | ||
OnCollectionChanged(source, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); | ||
} | ||
|
||
/// <summary> | ||
/// Removes a range of items from the specified observable collection quickly. | ||
/// </summary> | ||
/// <param name="sourceRange">The list of items to remove from the target collection.</param> | ||
/// <param name="target">The observable collection from which the items will be removed.</param> | ||
/// <exception cref="InvalidCastException">Thrown when the backing list of the target collection cannot be cast to a List{T}.</exception> | ||
/// <remarks> | ||
/// This method directly manipulates the backing list of the observable collection to remove the specified items, | ||
/// and then fires the necessary property changed and collection changed events to update any bindings. | ||
/// </remarks> | ||
internal static void RemoveItemsFast(List<T> sourceRange, ObservableCollection<T> target) | ||
{ | ||
// Get the backed list instance of the collection | ||
List<T> targetBackedList = GetBackedCollectionList(target) as List<T> ?? throw new InvalidCastException(); | ||
|
||
// Get the count and iterate the reference of the T from the source range | ||
ReadOnlySpan<T> sourceRangeSpan = CollectionsMarshal.AsSpan(sourceRange); | ||
int len = sourceRangeSpan.Length - 1; | ||
for (; len >= 0; len--) | ||
{ | ||
// Remove the reference of the item T from the target backed list | ||
_ = targetBackedList.Remove(sourceRangeSpan[len]); | ||
} | ||
|
||
// Fire the changes event | ||
RefreshAllEvents(target); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
CollapseLauncher/Classes/Extension/UIElementExtensions.UnsafeAccessorExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Microsoft.UI.Input; | ||
using Microsoft.UI.Xaml; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Collections.Specialized; | ||
using System.Runtime.CompilerServices; | ||
|
||
#nullable enable | ||
namespace CollapseLauncher.Extension | ||
{ | ||
internal static partial class UIElementExtensions | ||
{ | ||
/// <summary> | ||
/// Set the cursor for the element. | ||
/// </summary> | ||
/// <param name="element">The <seealso cref="UIElement"/> member of an element</param> | ||
/// <param name="inputCursor">The cursor you want to set. Use <see cref="InputSystemCursor.Create"/> to choose the cursor you want to set.</param> | ||
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = "set_ProtectedCursor")] | ||
internal static extern void SetCursor(this UIElement element, InputCursor inputCursor); | ||
|
||
/// <summary> | ||
/// Set the cursor for the element. | ||
/// </summary> | ||
/// <param name="element">The <seealso cref="UIElement"/> member of an element</param> | ||
/// <param name="inputCursor">The cursor you want to set. Use <see cref="InputSystemCursor.Create"/> to choose the cursor you want to set.</param> | ||
internal static ref T WithCursor<T>(this T element, InputCursor inputCursor) where T : UIElement | ||
{ | ||
element.SetCursor(inputCursor); | ||
return ref Unsafe.AsRef(ref element); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.