festival icon indicating copy to clipboard operation
festival copied to clipboard

"The Loop"

Open hinto-janai opened this issue 1 year ago • 0 comments

What

The main multi-threaded audio metadata and parsing loop ("The Loop") requires that each thread knows if an Artist/Album has already been seen, so that it can branch, create what it needs, and append it to the already existing Vec (or push a new one).

Not only does that have to be synced, but the inserted indices must also be in sync.

This means that until the thread has finished construction and inserted the data, it must hold onto a lock:

https://github.com/hinto-janai/festival/blob/70ab8c6f4a625cdefa744353a827efb19b6026eb/src/ccd/metadata.rs#L206

Problem

Most of the variables used for construction are already in scope so it probably doesn't amount for much wasted time, but it still could be better. There are most likely cheaper and lockless ways (atomics) to signal to other threads all the context needed.

Other problems

"The Loop" is way too long, has tons of duplicated code, and is very non-functional (much harder to test).

The whole Collection construction pipeline (not just including "The Loop") should be rethought... eventually.

hinto-janai avatar May 11 '23 01:05 hinto-janai