Skip to content

Many chained concat() calls can cause trace to fail #314

Open
@superdav42

Description

@superdav42

As a result of #198

Any js file with many chained concat() calls will take an eternity to trace.

A file with

var it = 'string'
	.concat('Another String 1', 'more 1')
	.concat('Another String 2', 'more 2')
	.concat('Another String 3', 'more 3')
	.concat('Another String 4', 'more 4')
	.concat('Another String 5', 'more 5')
	.concat('Another String 6', 'more 6')
	.concat('Another String 7', 'more 7')
	.concat('Another String 8', 'more 8')
	.concat('Another String 9', 'more 9')
	.concat('Another String 10', 'more 10')
	.concat('Another String 11', 'more 11')
	.concat('Another String 12', 'more 12')
	.concat('Another String 13', 'more 13')
	.concat('Another String 14', 'more 14')
	.concat('Another String 15', 'more 15')
	.concat('Another String 16', 'more 16')
	.concat('Another String 17', 'more 17')
	.concat('Another String 18', 'more 18')
	.concat('Another String 19', 'more 19')
	.concat('Another String 20', 'more 20')
	.concat('Another String 21', 'more 21')
	.concat('Another String 22', 'more 22');
console.log(it);

will take 10+ secs to trace using node v16.15.0 . Each additional .concat() will double the time required. Which means the algorithm used is Big O (2^n).

time node out/cli.js print input.js 
FILELIST:
package.json
input.js



real	0m11.048s
user	0m11.084s
sys	0m0.091s

I tried to find a solution but do not understand the code well enough to know what to change. This bug makes this project unusable for our project which uses many template literals. Babel/preset-env compiles these literals to .concat() chains. See https://babeljs.io/docs/en/babel-plugin-transform-template-literals for more. There's hundreds chained together in the large final file which you can see on NPM but the above is enough to reproduce the problem. This package in included in a seperate NEXT js project which uses @vercel/nft as part of it's build process but that build is hanging because of all the concat() it's trying to walk through.

Please make walking concat() more efficient someway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions