Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only read unbuffered when we read the whole file #13197

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions packages/filesystem/src/browser/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,7 @@ export class FileService {
async read(resource: URI, options?: ReadTextFileOptions): Promise<TextFileContent> {
const [bufferStream, decoder] = await this.doRead(resource, {
...options,
// optimization: since we know that the caller does not
// care about buffering, we indicate this to the reader.
// this reduces all the overhead the buffered reading
// has (open, read, close) if the provider supports
// unbuffered reading.
preferUnbuffered: true
preferUnbuffered: this.shouldReadUnbuffered(options)
});

return {
Expand Down Expand Up @@ -888,17 +883,25 @@ export class FileService {
options.mtime < stat.mtime && options.etag !== etag({ mtime: options.mtime /* not using stat.mtime for a reason, see above */, size: stat.size });
}

protected shouldReadUnbuffered(options?: ReadFileOptions): boolean {
// optimization: since we know that the caller does not
// care about buffering, we indicate this to the reader.
// this reduces all the overhead the buffered reading
// has (open, read, close) if the provider supports
// unbuffered reading.
//
// However, if we read only part of the file we still
// want buffered reading as otherwise we need to read
// the whole file and cut out the specified part later.
return options?.position === undefined && options?.length === undefined;
}

async readFile(resource: URI, options?: ReadFileOptions): Promise<FileContent> {
const provider = await this.withReadProvider(resource);

const stream = await this.doReadAsFileStream(provider, resource, {
...options,
// optimization: since we know that the caller does not
// care about buffering, we indicate this to the reader.
// this reduces all the overhead the buffered reading
// has (open, read, close) if the provider supports
// unbuffered reading.
preferUnbuffered: true
preferUnbuffered: this.shouldReadUnbuffered(options)
});

return {
Expand Down
Loading