oxc icon indicating copy to clipboard operation
oxc copied to clipboard

feat(mangler): mangle private class names

Open camc314 opened this issue 10 months ago โ€ข 5 comments

$ cat test.js
class Foo {
  constructor(k) {
    this.#kasd = k;
  }

  getK() {
    return this.#kasd;
  }
}
class Foo2 {
  constructor(k) {
    this.#kasd = k;
  }

  getK() {
    return this.#kasd;
  }
}

export { Foo, Foo2 };
$ cargo run -p oxc_minifier --example minifier -- --mangle
   Compiling oxc_mangler v0.51.0 (/Users/cameron/github/Boshen/oxc/crates/oxc_mangler)
   Compiling oxc_minifier v0.51.0 (/Users/cameron/github/Boshen/oxc/crates/oxc_minifier)
    Finished `dev` profile [unoptimized] target(s) in 0.96s
     Running `target/debug/examples/minifier --mangle`
class Foo {
        constructor(e) {
                this.#e = e;
        }
        getK() {
                return this.#e;
        }
}
class Foo2 {
        constructor(e) {
                this.#e = e;
        }
        getK() {
                return this.#e;
        }
}
export { Foo, Foo2 };

No diff on cargo misize. looks like non of the test suite has classes with private class members

camc314 avatar Feb 21 '25 16:02 camc314


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

camc314 avatar Feb 21 '25 16:02 camc314

CodSpeed Performance Report

Merging #9279 will degrade performances by 88.4%

Comparing c/02-21-feat_mangler_mangle_private_class_names (9106d71) with main (4ad328b)

Summary

โŒ 3 regressions
โœ… 30 untouched benchmarks

:warning: Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
โŒ mangler[antd.js] 16.2 ms 139.3 ms -88.4%
โŒ mangler[react.development.js] 299.4 ยตs 1,766.4 ยตs -83.05%
โŒ mangler[typescript.js] 39.8 ms 280.4 ms -85.79%

codspeed-hq[bot] avatar Feb 21 '25 16:02 codspeed-hq[bot]

This adds an additional AST pass, but how come it's not shown on the benchmark ๐Ÿค” ?

Boshen avatar Feb 23 '25 01:02 Boshen

so i implemented this inside: https://github.com/oxc-project/oxc/blob/82c354a1c23d0581c5be94ed50317291f39102fd/crates/oxc_minifier/src/lib.rs#L48 minifier::build. but that fn doesn't run when doing the benches. we run the mangler/minifier explicitly.

i think i could either:

  1. move this directly into the mangler
  2. move this as a minifier pass probably 1 is better?

camc314 avatar Feb 23 '25 22:02 camc314

  • move this directly into the mangler

Yeah this seems better. We can also add a flag (turned off by default) to enable this.

Boshen avatar Feb 23 '25 23:02 Boshen