Skip to content
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

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

Open
superdav42 opened this issue Oct 11, 2022 · 1 comment · May be fixed by #422
Open

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

superdav42 opened this issue Oct 11, 2022 · 1 comment · May be fixed by #422
Labels
bug Something isn't working

Comments

@superdav42
Copy link

superdav42 commented Oct 11, 2022

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.

superdav42 added a commit to superdav42/proskomma-js that referenced this issue Oct 11, 2022
@styfle styfle added the bug Something isn't working label Oct 11, 2022
DanielC-N pushed a commit to mvahowe/proskomma-js that referenced this issue Oct 12, 2022
@styfle styfle linked a pull request Jun 3, 2024 that will close this issue
@styfle
Copy link
Member

styfle commented Jun 3, 2024

Thanks for reporting this issue!

I created a PR with a fix #422

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants