-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core: faster saveTrace by streaming 500 events at a time #5387
Conversation
lighthouse-core/lib/asset-saver.js
Outdated
for (const event of eventsIterator) { | ||
yield `,\n ${JSON.stringify(event)}`; | ||
eventsJSON += `,\n ${JSON.stringify(event)}`; | ||
if (--eventsRemaining === 0) { |
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.
inline --x ===
always makes me think too much, WDYT about a separate statement :)
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.
it's also possible messing with the stream these are pushed into would improve things in addition to or instead of this (would avoid the concat + flattening before writing to disk), but improvement is substantial so LGTM :)
* very large traces. | ||
* Generates a JSON representation of traceData line-by-line to avoid OOM due to very large traces. | ||
* COMPAT: As of Node 9, JSON.parse/stringify can handle 256MB+ strings. Once we drop support for | ||
* Node 8, we can 'revert' PR #2593. See https://stackoverflow.com/a/47781288/89484 |
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.
Once we drop support for Node 8, we can 'revert' PR #2593
not sure if we actually want to anymore...we like the event-per-line formatting, right?
(We could consider shipping the pretty-json-stringify
we just used in the snyk snapshot thing—no dependencies and 2.43KB before minification!—but it looks like using it on large traces will depend on Node 9 as well)
asset-saver-test.js goes from 12.5s to 7.9s.
cc #2593 #1685