Skip to content

Atomic write should not be enabled for all usages of vscode-userdata #192970

Closed

Description

While looking into Peng Lyu (@rebornix) question in #167719 (comment), I noticed how now all writes triggered from vscode-userdata scheme have atomic: true:

writeFile(resource: URI, content: Uint8Array, opts: IFileWriteOptions): Promise<void> {
if (!isObject(opts.atomic) && hasFileAtomicWriteCapability(this.fileSystemProvider)) {
opts = { ...opts, atomic: { postfix: '.vsctmp' } };
}
return this.fileSystemProvider.writeFile(this.toFileSystemResource(resource), content, opts);
}

Since backups use this scheme, every time an editor is dirty and backs up, it will write atomically. I think we need to be careful here because atomic writes have a significant performance overhead in that they write the entire contents in one VSBuffer to disk at once and skip streaming.

For now I would suggest to really scope atomic: true only to those specific cases we wanted to fix, such as settings.

Steps:

  • open a file
  • make it dirty
  • notice how DiskFileSystemProvider.doWriteFileAtomic is triggered with the entire contents

Activity

  1. added
    important
    on Sep 13, 2023
  2. sandy081 commented on Sep 13, 2023

    @sandy081
    Member

    Since backups use this scheme...

    I was not expecting this. Why is backups using this scheme? I believe backups are not part of user data.

  3. bpasero commented on Sep 13, 2023

    @bpasero
    ContributorAuthor

    Sandeep Somavarapu (@sandy081) yeah also came to my surprise to be honest. But maybe so that it works in web?

  4. sandy081 commented on Sep 13, 2023

    @sandy081
    Member

    yeah, that could be the reason. Is it possible not to use userdata scheme in desktop?

  5. bpasero commented on Sep 13, 2023

    @bpasero
    ContributorAuthor

    Sandeep Somavarapu (@sandy081) I guess so, but not sure about the implications? To use that scheme, came in from your change in 79c4f10#diff-606a69dffd023e82747f7c6e0bbf3226dae1ec9f6dda1eef1f586509d958ec7eR36

    I still think its not necessarily bad that backups use this scheme, in the end it is also user data. I just feel we need to limit where atomic writes apply, e.g. by having a static map of well known paths or files.

  6. rebornix commented on Sep 14, 2023

    @rebornix
    Contributor

    While testing medium size files, I found backing up dirty files can cause the UI to freeze as it's not streamed, the whole process is stuck at encoding the whole string. As you can see in the perf log below, the file saving (the right side many small blocks) is doing fine as it's chunk-by-chunk so it doesn't hurt the frame rate.

    image
  7. added a commit that references this issue on Sep 14, 2023
    d6fe823
  8. sandy081 commented on Sep 14, 2023

    @sandy081
    Member

    Scoped atomic write to following resources:

    • Settings
    • Keybindings
    • Tasks
    • Extensions
  9. added
    unreleased
    on Sep 14, 2023
  10. added a commit that references this issue on Sep 14, 2023
    3b60c12
  11. added
    insiders-released
    and removed
    unreleased
    on Sep 15, 2023
  12. locked and limited conversation to collaborators on Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

file-ioimportantinsiders-released

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions