festival icon indicating copy to clipboard operation
festival copied to clipboard

`CCD` - No-clone save

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

What

CCD needs to save Collection to disk before the art is converted from bytes into the frontend-specific type.

GUI's art type: RetainedImage makes it extremely difficulty to recover the original bytes after conversion, so the Collection must somehow be saved in the "byte" state.

Problem

If CCD stops to save to disk before conversion, the user must also wait that much additional time.

Ideally, CCD would blast through the steps, return the full Collection to Kernel so that Collection construction time from the user's perspective is a fast as possible.

After CCD has sent a pointer off to Kernel, CCD would save it to disk in the background.

The issue is that after the Vec<u8> -> RetainedImage conversion, it is extremely difficult to recover the initial bytes, which is what we need to actually save to disk.

Bad solution

CCD currently:

  1. .clone()'s the Collection while it is in the "bytes" state
  2. Proceeds through the conversion steps
  3. Returns the converted Collection to Kernel
  4. Saves the previously cloned "byte" copy of Collection to disk
// Our `Collection` is still in the "byte" state, clone it.
let collection_for_disk = collection.clone();

// Now, convert the art bytes to higher level types.
let collection = convert(collection); 

// Send it to Kernel.
send(collection); // <- From the `GUI`'s perspective, the process is done here.

// Now, save the "byte" version to disk.
save(collection_for_disk);

This means we are holding 2 full copies of Collection in memory during this window.

The .clone() time is non-trivial as well, accounting for around 10% of the total Collection creation time.

Ideal solution

CCD should somehow recover the raw bytes after conversion and save that to disk.

hinto-janai avatar May 09 '23 17:05 hinto-janai