Skip to content

Commit

Permalink
perf(compiler): avoid copying from prototype while cloning an object (#…
Browse files Browse the repository at this point in the history
…31638)

This commit updates the `_clone` function of the `_ApplySourceSpanTransformer` class, where the for-in loop was used, resulting in copying from prototype to own properties, thus consuming more memory. Prior to NodeJS 12 (V8 versions before 7.4) there was an optimization that was improving the situation and since that logic was removed in favor of other optimizations, the situation with memory consumption caused by the for-in loop got worse. This commit adds a check to make sure we copy only own properties over to cloned object.

Closes #31627.

PR Close #31638
  • Loading branch information
AndrewKushnir authored and kara committed Jul 23, 2019
1 parent b31a292 commit 24ca582
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/compiler/src/output/output_ast.ts
Expand Up @@ -1464,7 +1464,7 @@ class _ApplySourceSpanTransformer extends AstTransformer {
constructor(private sourceSpan: ParseSourceSpan) { super(); }
private _clone(obj: any): any {
const clone = Object.create(obj.constructor.prototype);
for (let prop in obj) {
for (let prop of Object.keys(obj)) {
clone[prop] = obj[prop];
}
return clone;
Expand Down

0 comments on commit 24ca582

Please sign in to comment.