SmartAddresser icon indicating copy to clipboard operation
SmartAddresser copied to clipboard

Optimize DependentObjectBasedAssetFilter by Using HashSet and Avoiding Redundant Dependency Collection

Open CeejayZSmith opened this issue 8 months ago • 0 comments

This filter can get quite slow when there are thousands of assets in a project.

This change refactors DependentObjectBasedAssetFilter to improve performance and simplify logic: • Replaced List with HashSet for _dependentAssetPaths to ensure uniqueness and provide faster lookups. • Added a check to skip processing an asset if its dependencies have already been collected. • Replaced AddRange with a loop to add dependencies directly to the HashSet.

This should reduce unnecessary allocations and redundant entries, especially in large asset sets, and make the filtering logic more efficient.

Operation List<T> HashSet<T>
Check if element exists (Contains) O(n) O(1)
Add element O(1) O(1)
Enforce uniqueness Manual (Distinct() call, O(n log n)) Automatic during Add (O(1))

CeejayZSmith avatar Apr 19 '25 10:04 CeejayZSmith