Closed abchatra closed 1 year ago
Original issue was filed here and asked to move to this repo: https://github.com/microsoft/vscode-dev/issues/852
The size of the payload is in 10-15 MB. However, it is not the network speed which is blocking this (Gbps).
Also, note if we invoke similar project through the route, the load is fast (5-10 seconds)
We implement virtual file system in this case and hence this scenario is not impacted. So likely culprit is the file system interaction.
Unfortunately the source code for that extension seems closed source and not open source, at least I cannot see it. I wonder if the extension could speed things up by using the file service in parallel and not in sequence.
I am not able to reproduce slow writes locally. I can write 100mb
of data in 5 seconds
to disk.
Here is my sample extension code:
import * as vscode from 'vscode';
const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n';
function randomChar() {
return alphabet[randomInt(alphabet.length)];
}
function randomInt(bound: number) {
return Math.floor(Math.random() * bound);
}
function randomStr(len: number) {
if (len === null) {
len = 10;
}
return (function () {
let j, ref;
const results = [];
for (
j = 1, ref = len;
1 <= ref ? j < ref : j > ref;
1 <= ref ? j++ : j--
) {
results.push(randomChar());
}
return results;
})().join('');
}
export function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "create-random-files" is now active in the web extension host!');
let disposable = vscode.commands.registerCommand('create-random-files.helloWorld', async () => {
vscode.window.showInformationMessage('Hello World from Create Random Files in a web extension host!');
const start = Date.now();
const promises = [];
for (let i = 0; i < 1000; i++) {
const randomFile = vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, `somefile-${i}.txt`);
promises.push(vscode.workspace.fs.writeFile(randomFile, new TextEncoder().encode(randomStr(100000))));
}
await Promise.allSettled(promises);
console.log(`Took ${Date.now() - start}ms to create 1000 files`);
});
context.subscriptions.push(disposable);
}
export function deactivate() { }
Which I run in a chrome instance via npx @vscode/test-web --extensionDevelopmentPath=$extensionLocation
where $extensionLocation
is a local web extension I created via yo code
.
I do see however 3x slowness when I do not create all the files in parallel but in sequence, so that seems to be something maybe the Make-Code extension could check.
I really need a repro here that is minimal so please come back with steps how to reproduce.
@bpasero I have given access to this repo.
Apologies, we are in the process of making vscode-makecode opensource. It should be done soon.
@riknoll @jwunderl can you please point to the relevant code here.
Thanks, waiting for a minimal repro. Note that we cannot really review other peoples code.
I understand, we will work on small repro. Thank you for the directions .
@bpasero When I run the sample extension code above with a new yo code
web extension served via npx @vscode/test-web
I'm seeing it take 2-3 minutes on my work device when saving to a local folder.
where the folder is empty to start with
I ran it again with the chromium dev tools performance profiler on and it took 252.428 seconds, let me know and I can send over the profile / any other info that can help. The majority of time is listed as 'idle' while the promises were running and populating the folder:
I have a sample I had written up that more closely matches our use case but the result is the same as the sample you gave (just adding in folders and a mkdirp), just leaving collapsed below in case it's helpful.
Can you also try on a OS such as macOS or Linux, maybe it is Windows related. If it is OS specific then it sounds like a Chrome issue or maybe AntiVirus/Defender and then VS Code will not be able to do anything about it.
Btw I can confirm it is also much slower for me on Windows, with times around 150s
. I can only speculate that there is an issue with the Chrome implementation on Windows that makes this slower, because we have no windows specific code for creating the files.
Here is our code:
One thing we could experiment with is to implement stream based writing, because today we write everything at once (the full contents). However, typically writing everything at once is faster, not slower, just consuming more memory...
As a starter, I filed a Chrome issue to hear back if we do something wrong: https://bugs.chromium.org/p/chromium/issues/detail?id=1427148
Thanks so much @bpasero !
Closing as upstream. See discussion in https://bugs.chromium.org/p/chromium/issues/detail?id=1427148
Repro steps
Desktop client takes less than 5 seconds
Gif below with side by side comparison with desktop client:
I am unsure if this is browser API issue or VSCode.dev issue. Version: 1.76.2 Commit: ee2b180d582a7f601fa6ecfdad8d9fd269ab1884 User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.44 Embedder: vscode.dev