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
Add mapDocInPlace to modify the doc without creating unnecessary copies #6622
Conversation
src/language-js/embed.js
Outdated
function escapeTemplateCharacters(doc, raw) { | ||
return mapDoc(doc, currentDoc => { | ||
function escapeTemplateCharacters(doc, raw, mapInPlace) { | ||
const mapFunc = mapInPlace ? mapDocInPlace : mapDocInPlace; |
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.
This doesn't look good.
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 the other hand, escapeTemplateCharacters
isn't exported and isn't used anywhere else, so a comment should suffice instead of this extra parameter.
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.
That ternary had an error in anyway that I missed - it used mapDocInPlace
for both options. I've pushed a new commit which removes the extra parameter and just adds a comment that the original doc
is modified.
How do you measure the memory usage? I'm on Windows 10 64, testing 1.18.2 on a bundle with 100k lines: prettier --loglevel debug --debug-repeat 1000 bundle.js > nul and the memory usage does not even reach 2GB. |
Are the line endings in your bundle.js just |
I replaced the line endings with |
Reproduced it with your file. 👍 |
status? |
Fixed by #7891 |
This change aims to reduce memory usage, which was reaching over 8GB when processing one .js file (~2k lines, 104KB size) in our project and giving a
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
error. ThemapDoc
function was creating new objects for everything it processed, and is used to convert end of line characters when the line ending is notlf
. Creating new objects for a lot of the doc is unnecessary when the originaldoc
object is not used after themapDoc
call, so this function modifies the original object in place instead of creating new copies.Note that, because this new function modifies the original, it has only been used where we have identified it is safe to do so. Other places could benefit from it, and we've also added another parameter to
escapeTemplateCharacters
so that the caller can be explicit as to whether or not to use the new in place version.docs/
directory)CHANGELOG.unreleased.md
file following the template.