Increase performance of media syncs

Is your feature request related to a problem? Please describe.
I noticed media syncs between devices taking much longer than expected.

My ~1.5 GB collection took >5 minutes to sync on my 100MB/s download connection, which felt much slower than necessary.

Poking a bit into the rslib, it seems like we have these constants that limit bandwidth. The git log shows these values used to be higher ~10 years ago, got bump down in 2014 in this commit, and these values were carried over in the core re-write.

Please correct me if I’m mistaken here.

Describe the solution you’d like

If possible, increase these values.

// anki/rslib/src/sync/media/mod.rs

...

pub static MAX_MEDIA_FILES_IN_ZIP: usize = 25;

/// If reached, no further files are placed into the zip.

pub static MEDIA_SYNC_TARGET_ZIP_BYTES: usize = (2.5 * 1024.0 * 1024.0) as usize;

It’ll add some complexity, but it would also improve latency to send batches with multiple threads and process them concurrently. My current understanding is that this loop is sequential and could be parallelized.

1 Like

Happy to submit a PR myself with some guidance if this seems like an improvement!

Perhaps those slowdowns and restrictions are intentional? Currently AnkiWeb syncs are provided free of charge to all Anki users, so they explain in their FAQs that they may add paid options if server funding becomes insufficient.

2 Likes

My understanding is that costs should be the same since hosting providers usually price egress by bytes sent. i.e. 1GB sent as 400 batches of 2.5MB costs the same as 10 batches of 100MB

In fact, I think by sending more batches than necessary, we make the transfer slightly more expensive. Each requests has header information, so if we can make our batches larger we have less overhead.

My guess for why these constants were set to the values they were in 2014 is that hosting hardware and network infrastructure was worse back then (e.g. 3g network speeds, slower CPUs, fewer cores, etc). Hardware has gotten much better since 2014.

3 Likes

I logged this on Bump media syncing constants? · Issue #4467 · ankitects/anki · GitHub

Please wait for dae to take a look.

4 Likes

My guess is that if the sync speed increases users might sync more frequently.
e.g. it takes users 5 minutes to sync, and since this is inconvenient, they only sync 2 times per day. The improved version takes 2 minutes and since this is more convenient and easier, users sync 4 times per day.