swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.25k stars 1.23k forks source link

Infinite loop detected (current pass = 31)', ecmascript/minifier/src/compress/mod.rs:229:13 #2028

Closed mischnic closed 3 years ago

mischnic commented 3 years ago

Describe the bug

thread '<unnamed>' panicked at 'Infinite loop detected (current pass = 31)', ecmascript/minifier/src/compress/mod.rs:229:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
/Users/niklas/Documents/_dev/_git/parcel/swc/index.js:59
        return bindings.minifySync(src, toBuffer(opts !== null && opts !== void 0 ? opts : {}));
                        ^

Error: Infinite loop detected (current pass = 31)

Example

const code =
`
function isSymbol(s) {
    return s != null;
}

function isKey(value, object) {
    if (value == null || isSymbol(value)) {
        return true;
    }
    return false;
}

module.exports = isKey;
`;

const minified = swc.minifySync(code, {
    sourceMap: false,
    mangle: true,
    compress: true,
});

Version In both 026c21ec68b8c32a2768231c4e89e7f618a77dab and 1.2.74

mischnic commented 3 years ago

By the way, here are the benchmark results now:

minifiying node_modules/.pnpm/vue@2.6.12/node_modules/vue/dist/vue.runtime.common.dev.js
swc: 139ms, terser: 891ms
swc: 101826 bytes, terser: 94905 bytes
swc is 0.932x smaller and 6.41x faster

minifiying node_modules/.pnpm/react@17.0.1/node_modules/react/cjs/react.development.js
swc: 25ms, terser: 200ms
swc: 24256 bytes, terser: 23118 bytes
swc is 0.953x smaller and 8.00x faster

minifiying node_modules/.pnpm/moment@2.29.1/node_modules/moment/moment.js
swc: 61ms, terser: 477ms
swc: 63276 bytes, terser: 59211 bytes
swc is 0.936x smaller and 7.82x faster

minifiying node_modules/.pnpm/d3@6.3.1/node_modules/d3/dist/d3.js
swc: 527ms, terser: 2012ms
swc: 311488 bytes, terser: 267985 bytes
swc is 0.860x smaller and 3.82x faster

minifiying node_modules/.pnpm/jquery@3.5.1/node_modules/jquery/dist/jquery.js
swc: 140ms, terser: 520ms
swc: 97365 bytes, terser: 89875 bytes
swc is 0.923x smaller and 3.71x faster

minifiying node_modules/.pnpm/terser@5.7.0/node_modules/terser/dist/bundle.min.js
swc: 318ms, terser: 1341ms
swc: 430975 bytes, terser: 410973 bytes
swc is 0.954x smaller and 4.22x faster

minifiying node_modules/.pnpm/antd@4.16.1_react@17.0.1/node_modules/antd/dist/antd.js
swc: 995ms, terser: 10631ms
swc: 2488985 bytes, terser: 2751763 bytes
swc is 1.106x smaller and 10.68x faster

minifiying node_modules/.pnpm/echarts@5.1.1/node_modules/echarts/dist/echarts.js
swc: 2123ms, terser: 5350ms
swc: 1180534 bytes, terser: 1000395 bytes
swc is 0.847x smaller and 2.52x faster

minifiying node_modules/.pnpm/victory@35.8.4/node_modules/victory/dist/victory.js
swc: 459ms, terser: 3119ms
swc: 817468 bytes, terser: 870615 bytes
swc is 1.065x smaller and 6.80x faster

swc is always faster and always within 85-95% of terser's output size. For antd, swc's output is smaller than terser (Using a local build of swc via yarn build, which should be optimized)

kdy1 commented 3 years ago

Thanks! I didn't try node-side benchmark :)

swc-bot commented 2 years ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.