-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
If I have a really big file like:
var foo = class {
doesntReallyMatter(){}
}
... few thousand lines of things ...
/*
@license
*/
... maybe some other stuffand I compile it with compact:true (or the auto-compact-erizer kicks in because it's >100k, with or without comments:false because @license is always preserved), code generation takes ages (many minutes, versus seconds if the license comment isn't there)
It looks like it's coming from the trim-right in Buffer#get (replacing that line with return this.buf makes everything fast again).
By the look of it, trim-right uses a regex that's quadratically bad if you have massive expanses of whitespace that aren't at the end of the string, which is what happens in this case because the output looks something like this (with potentially enormous amounts of whitespace to align the comment):
foo something [lots and lots of stuff, many hundreds of thousands of characters] /*
@license
*/ rest of the thingsI'm not sure what you'd consider to be the most elegant solution here - changing Buffer#get to something like:
get(){
var tail = this.buf.length;
while(/[\s\uFEFF\xA0]/.test(this.buf.charAt(tail - 1))){
tail--;
}
return this.buf.slice(0, tail);
}... seems to work for me (although it may or may not have an off-by-one error because I've written it fairly quickly). Alternatively getting rid of the indentation of comments in compact mode would probably achieve the same effect.