Skip to content
Browse files

perf(compiler): avoid copying from prototype while cloning an object (#…


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 18, 2019
1 parent 5f4254c commit 1f3daa03ab32b33c8e26625792edfe1e89c79853
Showing with 1 addition and 1 deletion.
  1. +1 −1 packages/compiler/src/output/output_ast.ts
@@ -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;

0 comments on commit 1f3daa0

Please sign in to comment.
You can’t perform that action at this time.