src: avoid deferred gc/cleanup for Buffer.from#38337
Closed
jasnell wants to merge 2 commits intonodejs:masterfrom
Closed
src: avoid deferred gc/cleanup for Buffer.from#38337jasnell wants to merge 2 commits intonodejs:masterfrom
jasnell wants to merge 2 commits intonodejs:masterfrom
Conversation
Previously, the code path would allocated a tracked ArrayBuffer that defers cleanup and deallocation of the underlying data with a SetImmediate. Avoid the unnecessary deferral by just allocating a `BackingStore` directly and writing into it. Fixes: nodejs#38300 Refs: nodejs#38336
This comment has been minimized.
This comment has been minimized.
addaleax
approved these changes
Apr 22, 2021
Co-authored-by: Anna Henningsen <anna@addaleax.net>
XadillaX
approved these changes
Apr 22, 2021
Contributor
XadillaX
left a comment
There was a problem hiding this comment.
After testing:
const str = 'x'.repeat(10000);
console.log('start', process.memoryUsage());
console.time('1');
for(let i = 0; i < 1e6; i++) {
Buffer.from(str); // memory leak happens here
if (i % 1e5 === 0) {
// await wait(100);
gc();
console.log('step', i, 'rss', process.memoryUsage().rss);
}
}
console.timeEnd('1');
gc();
console.log('end', process.memoryUsage());The new PR #38337 runs about 3.9s in my computer. And 39f42d1a2d (before using BackingStore) runs about 3.7s. I think this performance loss is acceptable.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Collaborator
Member
Author
|
@nodejs/build ... is there a known issue with the node-test-commit-arm-fanned cluster? It is failing consistently on multiple PRs |
Member
I cleaned up leftover node process on three of the pi 2's this morning. AFAIK things should be okay now. |
joyeecheung
approved these changes
Apr 23, 2021
Collaborator
Member
Author
|
@richardlau ... no joy it seems. See https://ci.nodejs.org/job/node-test-binary-arm-12+/10459/RUN_SUBSET=1,label=pi2-docker/console for #38331, for instance. |
targos
pushed a commit
that referenced
this pull request
Apr 24, 2021
Previously, the code path would allocated a tracked ArrayBuffer that defers cleanup and deallocation of the underlying data with a SetImmediate. Avoid the unnecessary deferral by just allocating a `BackingStore` directly and writing into it. Fixes: #38300 Refs: #38336 PR-URL: #38337 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Member
|
Landed in 720fdf2 |
targos
pushed a commit
that referenced
this pull request
Apr 29, 2021
Previously, the code path would allocated a tracked ArrayBuffer that defers cleanup and deallocation of the underlying data with a SetImmediate. Avoid the unnecessary deferral by just allocating a `BackingStore` directly and writing into it. Fixes: #38300 Refs: #38336 PR-URL: #38337 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
targos
pushed a commit
that referenced
this pull request
May 30, 2021
Previously, the code path would allocated a tracked ArrayBuffer that defers cleanup and deallocation of the underlying data with a SetImmediate. Avoid the unnecessary deferral by just allocating a `BackingStore` directly and writing into it. Fixes: #38300 Refs: #38336 PR-URL: #38337 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
targos
pushed a commit
that referenced
this pull request
Jun 5, 2021
Previously, the code path would allocated a tracked ArrayBuffer that defers cleanup and deallocation of the underlying data with a SetImmediate. Avoid the unnecessary deferral by just allocating a `BackingStore` directly and writing into it. Fixes: #38300 Refs: #38336 PR-URL: #38337 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
targos
pushed a commit
that referenced
this pull request
Jun 11, 2021
Previously, the code path would allocated a tracked ArrayBuffer that defers cleanup and deallocation of the underlying data with a SetImmediate. Avoid the unnecessary deferral by just allocating a `BackingStore` directly and writing into it. Fixes: #38300 Refs: #38336 PR-URL: #38337 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
/cc @addaleax @Daninet
Previously, the code path would allocated a tracked
ArrayBufferthat defers cleanup and deallocation of the underlying data with a nativeSetImmediate. Avoid the unnecessary deferral by just allocating aBackingStoredirectly and writing into it.This should be considered an alternative to #38336
Fixes: #38300
Refs: #38336