-
Notifications
You must be signed in to change notification settings - Fork 4.2k
chore: download browser downloads in-memory #35909
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
Open
mxschmitt
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
mxschmitt:in-memory-downloader
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+28
−40
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,20 +33,21 @@ const { promisify } = require('util') | |
const stream = require('stream') | ||
const yauzl = require('yauzl') | ||
|
||
const openZip = promisify(yauzl.open) | ||
const openZipFromBuffer = promisify(yauzl.fromBuffer) | ||
const pipeline = promisify(stream.pipeline) | ||
|
||
class Extractor { | ||
constructor (zipPath, opts) { | ||
this.zipPath = zipPath | ||
constructor (zipFile, opts) { | ||
/** @type {Buffer} */ | ||
this.zipFile = zipFile | ||
this.opts = opts | ||
} | ||
|
||
async extract () { | ||
debug('opening', this.zipPath, 'with opts', this.opts) | ||
debug('opening', `${this.zipFile.byteLength} bytes`, 'with opts', this.opts); | ||
|
||
this.zipfile = await openZip(this.zipPath, { lazyEntries: true }) | ||
this.canceled = false | ||
this.zipfile = await openZipFromBuffer(this.zipFile, { lazyEntries: true }); | ||
this.canceled = false; | ||
|
||
return new Promise((resolve, reject) => { | ||
this.zipfile.on('error', err => { | ||
|
@@ -55,7 +56,7 @@ class Extractor { | |
}) | ||
this.zipfile.readEntry() | ||
|
||
this.zipfile.on('close', () => { | ||
this.zipfile.on('end', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (!this.canceled) { | ||
debug('zip extraction complete') | ||
resolve() | ||
|
@@ -186,7 +187,7 @@ class Extractor { | |
} | ||
} | ||
|
||
module.exports = async function (zipPath, opts) { | ||
module.exports = async function (zipFile, opts) { | ||
debug('creating target directory', opts.dir) | ||
|
||
if (!path.isAbsolute(opts.dir)) { | ||
|
@@ -195,5 +196,5 @@ module.exports = async function (zipPath, opts) { | |
|
||
await fs.mkdir(opts.dir, { recursive: true }) | ||
opts.dir = await fs.realpath(opts.dir) | ||
return new Extractor(zipPath, opts).extract() | ||
return new Extractor(zipFile, opts).extract() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have numbers of how much do we save? I guess it'd be the most beneficial on Windows, but by how much? Also this means holding entire buffers in memory which might hit us if we finally decide to download in parallel. So I'm a bit hesitant changing this.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a M1 Pro Mac machine its a
9.55
% improvement and on a Windows DevBox its a11.71
% improvement. Both of these tests were made on a fast machine and using a SSD. I expect much higher improvements when we consider slow (e.g. HDD) or busy disks.re the comment for parallel downloads. If we assume to hold all our downloads in memory it would be
293 MB
on Windows which would be still manageable I'd say. This aligns well of how much Chromium takes when navigating to websites. Its even higher sometimes on busy websites.Used data
macOS M1 Pro
with file write:
with in-memory:
Windows DevBox 64GB RAM
with file write:
with in-memory:
results
Script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds plausible! This is on the critical path, so we should place this behind an opt-out flag.