Arlodotexe / strix-music

Combine any music sources into a single library. It's your music. Play it your way.
http://www.strixmusic.com
138 stars 4 forks source link

Metadata scanners should be using IAsyncEnumerable instead of Task{IEnumerable{T}} #156

Closed Arlodotexe closed 2 years ago

Arlodotexe commented 2 years ago

Background

In large part, the metadata scanners in the namespace StrixMusic.Sdk.FileMetadata.Scanners were created by many devs collectively, with loose coordination from @Arlodotexe.

Because of the way we developed this, we ran into a few unexpected problems in our first pass, namely that events were firing so quickly and so often that it overloaded the GC and caused the UI to be unresponsive when the debugger was attached, even when running in a background thread (all threads pause before GC can do cleanup).

We solve this by batching results on an event handler, then returning all the scanned metadata as an IEnumerable.

The problem

This API surface can be dramatically improved. Instead of using a Task that contains an IEnumerable of all the metadata, we should be using IAsyncEnumerable and returning the metadata as it's scanned.

This applies to both PlaylistMetadataScanner and AudioMetadataScanner.

We'll also need to evaluate what this means for file-based cores, and if it can be applied throughout the codebase so that each song appears in the UI as it's scanned, without overloading the GC.