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

es/minifier: assignment of mangled names is order dependent, not usage #10059

Closed
Le0Developer opened this issue Feb 20, 2025 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@Le0Developer
Copy link

Describe the bug

I have made a simple reproduction case with 100 functions, each used twice (to avoid inlining) and a single function which is used 100 times.
The function that is used over 100 times is assigned a longer name than a function that is only used twice, and thus wasting 98 bytes.

Input code

function dummy0() {}
function dummy1() {}
function dummy2() {}
function dummy3() {}
function dummy4() {}
function dummy5() {}
function dummy6() {}
function dummy7() {}
function dummy8() {}
function dummy9() {}
function dummy10() {}
function dummy11() {}
function dummy12() {}
function dummy13() {}
function dummy14() {}
function dummy15() {}
function dummy16() {}
function dummy17() {}
function dummy18() {}
function dummy19() {}
function dummy20() {}
function dummy21() {}
function dummy22() {}
function dummy23() {}
function dummy24() {}
function dummy25() {}
function dummy26() {}
function dummy27() {}
function dummy28() {}
function dummy29() {}
function dummy30() {}
function dummy31() {}
function dummy32() {}
function dummy33() {}
function dummy34() {}
function dummy35() {}
function dummy36() {}
function dummy37() {}
function dummy38() {}
function dummy39() {}
function dummy40() {}
function dummy41() {}
function dummy42() {}
function dummy43() {}
function dummy44() {}
function dummy45() {}
function dummy46() {}
function dummy47() {}
function dummy48() {}
function dummy49() {}
function dummy50() {}
function dummy51() {}
function dummy52() {}
function dummy53() {}
function dummy54() {}
function dummy55() {}
function dummy56() {}
function dummy57() {}
function dummy58() {}
function dummy59() {}
function dummy60() {}
function dummy61() {}
function dummy62() {}
function dummy63() {}
function dummy64() {}
function dummy65() {}
function dummy66() {}
function dummy67() {}
function dummy68() {}
function dummy69() {}
function dummy70() {}
function dummy71() {}
function dummy72() {}
function dummy73() {}
function dummy74() {}
function dummy75() {}
function dummy76() {}
function dummy77() {}
function dummy78() {}
function dummy79() {}
function dummy80() {}
function dummy81() {}
function dummy82() {}
function dummy83() {}
function dummy84() {}
function dummy85() {}
function dummy86() {}
function dummy87() {}
function dummy88() {}
function dummy89() {}
function dummy90() {}
function dummy91() {}
function dummy92() {}
function dummy93() {}
function dummy94() {}
function dummy95() {}
function dummy96() {}
function dummy97() {}
function dummy98() {}
function dummy99() {}
window.a = [dummy0, dummy1, dummy2, dummy3, dummy4, dummy5, dummy6, dummy7, dummy8, dummy9, dummy10, dummy11, dummy12, dummy13, dummy14, dummy15, dummy16, dummy17, dummy18, dummy19, dummy20, dummy21, dummy22, dummy23, dummy24, dummy25, dummy26, dummy27, dummy28, dummy29, dummy30, dummy31, dummy32, dummy33, dummy34, dummy35, dummy36, dummy37, dummy38, dummy39, dummy40, dummy41, dummy42, dummy43, dummy44, dummy45, dummy46, dummy47, dummy48, dummy49, dummy50, dummy51, dummy52, dummy53, dummy54, dummy55, dummy56, dummy57, dummy58, dummy59, dummy60, dummy61, dummy62, dummy63, dummy64, dummy65, dummy66, dummy67, dummy68, dummy69, dummy70, dummy71, dummy72, dummy73, dummy74, dummy75, dummy76, dummy77, dummy78, dummy79, dummy80, dummy81, dummy82, dummy83, dummy84, dummy85, dummy86, dummy87, dummy88, dummy89, dummy90, dummy91, dummy92, dummy93, dummy94, dummy95, dummy96, dummy97, dummy98, dummy99]
window.b = [dummy0, dummy1, dummy2, dummy3, dummy4, dummy5, dummy6, dummy7, dummy8, dummy9, dummy10, dummy11, dummy12, dummy13, dummy14, dummy15, dummy16, dummy17, dummy18, dummy19, dummy20, dummy21, dummy22, dummy23, dummy24, dummy25, dummy26, dummy27, dummy28, dummy29, dummy30, dummy31, dummy32, dummy33, dummy34, dummy35, dummy36, dummy37, dummy38, dummy39, dummy40, dummy41, dummy42, dummy43, dummy44, dummy45, dummy46, dummy47, dummy48, dummy49, dummy50, dummy51, dummy52, dummy53, dummy54, dummy55, dummy56, dummy57, dummy58, dummy59, dummy60, dummy61, dummy62, dummy63, dummy64, dummy65, dummy66, dummy67, dummy68, dummy69, dummy70, dummy71, dummy72, dummy73, dummy74, dummy75, dummy76, dummy77, dummy78, dummy79, dummy80, dummy81, dummy82, dummy83, dummy84, dummy85, dummy86, dummy87, dummy88, dummy89, dummy90, dummy91, dummy92, dummy93, dummy94, dummy95, dummy96, dummy97, dummy98, dummy99]

function other() {}
window.c = [other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other, other]

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": true
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": {
        "arguments": true,
        "arrows": true,
        "booleans": true,
        "booleans_as_integers": true,
        "collapse_vars": true,
        "comparisons": true,
        "computed_props": true,
        "conditionals": true,
        "dead_code": true,
        "directives": true,
        "drop_console": false,
        "drop_debugger": true,
        "evaluate": true,
        "expression": true,
        "hoist_funs": true,
        "hoist_props": true,
        "hoist_vars": true,
        "if_return": true,
        "join_vars": true,
        "keep_classnames": false,
        "keep_fargs": false,
        "keep_fnames": false,
        "keep_infinity": false,
        "loops": true,
        "negate_iife": true,
        "properties": true,
        "reduce_funcs": true,
        "reduce_vars": true,
        "side_effects": true,
        "switches": true,
        "typeofs": true,
        "unsafe": true,
        "unsafe_arrows": true,
        "unsafe_comps": true,
        "unsafe_Function": true,
        "unsafe_math": true,
        "unsafe_symbols": true,
        "unsafe_methods": true,
        "unsafe_proto": true,
        "unsafe_regexp": true,
        "unsafe_undefined": true,
        "unused": true,
        "const_to_let": true,
        "pristine_globals": true,
        "passes": 10
      },
      "mangle": {
        "toplevel": true,
        "keep_classnames": false,
        "keep_fnames": false,
        "keep_private_props": false,
        "ie8": false,
        "safari10": false
      }
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": true,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.10.18&code=H4sIAAAAAAAAA%2B3WzWoUURBA4b1PMUuFIN66v7XwSSQLTQxmkRmQhCDiu4vapyVw9iL0qqAWh%2F5m%2Bs6du6fzzeP95Xy6fXp4%2BPbu9ZvT9x%2Bv7l4siy3DltWWzZbdlsOW05bLlqkP7yQ1FUUVVRVlFXUVhRWVFaUVtYXawr8vtYXaQm2htlBbqC3UFmqraqtqq%2F4yqq2qraqtqq2qraqtqq2pramtqa35SVNbU1tTW1NbU1tTW1dbV1tXW1db958RtXW1dbV1tXW1DbUNtQ21DbUNtQ3%2FjVTbUNtQ21DbVNtU21TbVNtU21Tb9AtAbVNtU21LbUttS21LbUttS21LbctvN7UttaXaUm2ptlRbqi3VlmpLtaVf3Zvt%2Bf58e3l%2B%2B%2FH0%2FvThzx%2BSq%2B0C3GZss26zbbNvc2xzbnNtM%2BnsQYqFZKFZiBaqhWyhWwgXykE59melHJSDclAOykE5KAflSrlSrvvHQLlSrpQr5Uq5Uq6UG%2BVGuVFu%2BydMuVFulBvlRrlR7pQ75U65U%2B77l0e5U%2B6UO%2BVOeVAelAflQXlQHvt7QXlQHpQH5Ul5Up6UJ%2BVJeVKe%2BytHeVKelBflRXlRXpQX5UV5UV7720x5UU7KSTkpJ%2BWknJSTclLO%2FaDkNafw03EKj1N4nMJ%2FdQr%2FXpGXxy%2Bfv764IG9%2BHc3f66vTMY7xn43rn68mQh52EgAA&config=H4sIAAAAAAAAA52VwXKjMAyG732KDOce2sPu7PQB9rbP4HGwIM4ai7FkGqaTd68w0LKJyGEvmaBPQui3JH88HQ7Vmerq7fAhf%2BWht4kgfT2LhcbI9iKWCurOUp18z9XzSs80IU4ZiuU6g4ptaoFLEP1YvKuASCC2xgaCxdb56Jtxm6%2FGrk9AtLGJVd6XO4hMS7bnLUr4rtiPiAFsfECMJeMjQwtJ8aoxBNsTmMHquBOxPKGWYYKZwZk%2BYa%2Fy6Dx7jCLFPXVgnanRgYJ8gpr9AFqY5JKwSFLdvzJ%2FYwfH3LblhG%2BiYbAhW1ZywqUciHztPTuhJzZN1kSY2Y4CM9Sl9Y1JwDkp%2Bc7o407UXwApP1iiaLuiz60CxaORVtqHD0N9bKRdeVS49LZWZYRWJDXeN4qukzKQ2GtnmcDlGiZh632q60DegYGmkT7R6Lvn%2BqSl5LEHbBQgh2u175%2FtZm%2F%2BFjyNwj79LQWy2lmLQ2f5tAtp7I6oTdAaDHxCt8%2FlBBh3aZLFcOl3cY4OpB%2FAaR6ZNPs0nGwYTSjL8a4fZCTkhaYNeFQXQy%2FNXY7u9WUxXr82cWdjW%2BZ%2BszUZ%2BwADhP8flodUPniY2nsd8VsnD78Uq4gne%2FP1ZUVrJU%2Frb6mp6tDlTT2lPecL5Wf17bReH2t5lac%2Fa2C5la6fjTfCXuQGAAA%3D

SWC Info output

No response

Expected behavior

The other function at the bottom should receive a one-letter name.

Actual behavior

It receives a two letter name. Receiving a one letter name would save 98 bytes in this extreme example.

Version

1.10.18

Additional context

If the function declaration of other is moved to the top of the file, it receives a one-letter name.

@kdy1
Copy link
Member

kdy1 commented Feb 28, 2025

Actually this makes the gzipped size worse.

  • With patch:
   Compiling swc_ecma_minifier v12.0.1 (/Users/kdy1/projects/s/minifier/crates/swc_ecma_minifier)
    Finished `release` profile [optimized + debuginfo] target(s) in 51.32s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/antd.js`
File: ./benches/full/antd.js
  460274
    Finished `release` profile [optimized + debuginfo] target(s) in 0.20s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/d3.js`
File: ./benches/full/d3.js
   87422
    Finished `release` profile [optimized + debuginfo] target(s) in 0.18s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/echarts.js`
File: ./benches/full/echarts.js
  324091
    Finished `release` profile [optimized + debuginfo] target(s) in 0.14s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/jquery.js`
File: ./benches/full/jquery.js
   31678
    Finished `release` profile [optimized + debuginfo] target(s) in 0.15s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/lodash.js`
File: ./benches/full/lodash.js
   25164
    Finished `release` profile [optimized + debuginfo] target(s) in 0.16s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/moment.js`
File: ./benches/full/moment.js
   18646
    Finished `release` profile [optimized + debuginfo] target(s) in 0.19s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/react.js`
File: ./benches/full/react.js
    8180
    Finished `release` profile [optimized + debuginfo] target(s) in 0.22s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/terser.js`
File: ./benches/full/terser.js
  117125
    Finished `release` profile [optimized + debuginfo] target(s) in 0.19s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/three.js`
File: ./benches/full/three.js
  159168
    Finished `release` profile [optimized + debuginfo] target(s) in 0.18s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/typescript.js`
File: ./benches/full/typescript.js
  816663
    Finished `release` profile [optimized + debuginfo] target(s) in 0.14s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/victory.js`
File: ./benches/full/victory.js
  160660
    Finished `release` profile [optimized + debuginfo] target(s) in 0.20s
     Running `/Users/kdy1/projects/s/minifier/target/release/examples/minifier ./benches/full/vue.js`
File: ./benches/full/vue.js
   43041
~/projects/s/minifier/crates/swc_ecma_minifier kdy1/10059 59s                                                                                                                                             11:59:16 AM
❯
  • main:
   Compiling swc_ecma_minifier v12.0.1 (/Users/kdy1/projects/master-swc/crates/swc_ecma_minifier)
    Finished `release` profile [optimized + debuginfo] target(s) in 49.56s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/antd.js`
File: ./benches/full/antd.js
  456848
    Finished `release` profile [optimized + debuginfo] target(s) in 0.15s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/d3.js`
File: ./benches/full/d3.js
   86899
    Finished `release` profile [optimized + debuginfo] target(s) in 0.13s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/echarts.js`
File: ./benches/full/echarts.js
  320565
    Finished `release` profile [optimized + debuginfo] target(s) in 0.13s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/jquery.js`
File: ./benches/full/jquery.js
   30881
    Finished `release` profile [optimized + debuginfo] target(s) in 0.13s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/lodash.js`
File: ./benches/full/lodash.js
   25094
    Finished `release` profile [optimized + debuginfo] target(s) in 0.13s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/moment.js`
File: ./benches/full/moment.js
   18589
    Finished `release` profile [optimized + debuginfo] target(s) in 0.13s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/react.js`
File: ./benches/full/react.js
    8194
    Finished `release` profile [optimized + debuginfo] target(s) in 0.18s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/terser.js`
File: ./benches/full/terser.js
  116706
    Finished `release` profile [optimized + debuginfo] target(s) in 0.18s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/three.js`
File: ./benches/full/three.js
  158097
    Finished `release` profile [optimized + debuginfo] target(s) in 0.16s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/typescript.js`
File: ./benches/full/typescript.js
  812079
    Finished `release` profile [optimized + debuginfo] target(s) in 0.13s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/victory.js`
File: ./benches/full/victory.js
  157197
    Finished `release` profile [optimized + debuginfo] target(s) in 0.13s
     Running `/Users/kdy1/projects/master-swc/target/release/examples/minifier ./benches/full/vue.js`
File: ./benches/full/vue.js
   42654
~/projects/master-swc/crates/swc_ecma_minifier main* 57s

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2025
@kdy1 kdy1 modified the milestones: Planned, v1.11.5 Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants