WICG / file-system-access

Expose the file system on the user’s device, so Web apps can interoperate with the user’s native applications.
https://wicg.github.io/file-system-access/
Other
669 stars 66 forks source link

Closing Writable is Slow If Content Contains Certain Character Sequence #434

Closed tmpmachine closed 11 months ago

tmpmachine commented 11 months ago

Saving file content with certain character sequence such as <htmlscript> is twice as slow than without.

async function writeFile(fileHandle, contents) {
  const writable = await fileHandle.createWritable();
  await writable.write('<htmlscript>'); // 2-3x times slower than without when closing

  let then = new Date();

  await writable.close();

  let now = new Date();

  let elapsed = new Date(now - then).getTime();
  console.log(elapsed);
}

Test cases ;

Tested on blank project as well as File System Access API demo : https://googlechromelabs.github.io/text-editor/.

Tested on OS :

Changing the MIME type on file picker options also has no effect on this issue :

async function getNewFileHandle() {
  const options = {
    /*
    types: [
      {
        description: 'Text Files',
        accept: {
          'text/html': ['.html'],
        },
      },
    ],
    // */
  };
  let handle = await window.showSaveFilePicker(options);
  return handle;
}
a-sully commented 11 months ago

This discrepancy is likely due to Safe Browsing checks. You could test this by turning them off or writing to a file in the OPFS (for which Safe Browsing checks are not run)

Closing this issue because this is a question about the Chromium implementation. If there's more to this, please file a Chromium bug under the Blink>Storage>FileSystem component