-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Printing JS constructor function type causes out-of-memory error #29597
Comments
Wow, it actually runs V8 out of heap space, that's impressive 😮 |
I created a smaller repro in https://github.com/bowenni/heap-OOM-repro The relevant compiler options are |
Still crashes on 3.4 and typescript@next |
Also crashes with the unminified chart.js |
After shrinking the size of Chart.js considerably, I can see that the problem is that var Color = function (obj) {
this.values = { rgb: [1, 1, 1] }
};
Color.prototype = {
// .........
negate: function () {
var rgb = [];
for (var i = 0; i < 3; i++) {
rgb[i] = 255 - this.values.rgb[i];
}
this.setValues('rgb', rgb);
return this;
},
lighten: function (ratio) {
// .... When you ask for the type of
The root cause is that constructor functions don't create classes. This type shouldn't be created over and over again, but a better fix is to make constructor functions create real classes. |
Is there a workaround for this in the meantime? It's unclear on how one should proceed when they get this error. |
@dgreene1 I worked around the problem by setting |
That workaround (adding |
For reasons I don't think I'll ever understand, this is the line that was causing the issue:
Hopefully that helps someone to debug the root issue, which I'm sure has nothing to do with lodash. |
@dgreene1 You have a different issue if noErrorTruncation didn't work. lodash chaining methods were quite inefficient to compile until recently. Can you update your |
@sandersn I think if you look at your trimmed down example (based on |
That didn't fix it. So I refactored the chaining code out and it's working. |
The trimmed-down example no longer crashes, but both Chart.js and chart.min.js still crash. I'll try to find the remaining problem(s). |
Here's the trimmed down example that still crashes: function Color(obj) {
this.example = true
};
Color.prototype = {
negate: function () {return this;},
lighten: function (ratio) {return this;},
darken: function (ratio) {return this;},
saturate: function (ratio) {return this;},
desaturate: function (ratio) {return this;},
whiten: function (ratio) {return this;},
blacken: function (ratio) {return this;},
greyscale: function () {return this;},
clearer: function (ratio) {return this;},
toJSON: function () {return this.rgb();},
}; with this tsconfig: {
"compilerOptions": {
"noErrorTruncation": true,
"noImplicitAny": true,
"allowJs": true,
"outDir": "built"
},
"files": [
"./Chart.js",
]
} |
Is |
Removing one function, or even the body of one function, allows compilation to finish in about 12 seconds. |
@weswigham When changed to |
Oh, it's because we're trying to issue an error. If |
Ah, alright |
The root problem is We can patch typeToTypeNodeHelper to understand this structure, or we can make constructor functions create class types. I'd rather do the latter, although it's a big task, so I'm going to look at my other 3.6 bugs first. I'm not going to dupe this to the existing "make constructor functions into class types" bug because we might decide to solve this by adding a special case to typeToTypeNode. (#27328? #26883? There's not really a good issue for this anyway.) |
TypeScript Version: 3.2.2 and 3.3.0-rc
Search Terms:
heap out of memory
Code
First of all, I don't expect there to be a valid use case of what I'm describing below. In fact a miss configuration in my build settings lead me to this. However I don't expect TSC to completely crash. Also I found that TS 3.1 had no problems with the code below so this might be a regression of TS 3.2.
Steps to reproduce the heap OOM
node_modules/chart.js/dist
. You should findChart.min.js
there.tsconfig.json
with the following contenttsc -p tsconfig.json --outDir foo
and see the JavaScript heap out of memory thrown.Expected behavior:
Emits a file
foo/Chart.min.js
.TS 3.1.6 finishes this in 1.7 seconds without any errors.
Actual behavior:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Playground Link:
N/A
Related Issues:
This looks similar to #29326 and #29511 but I don't understand it deep enough to tell if it's a duplicate.
The text was updated successfully, but these errors were encountered: