Skip to content

feat(minifier): remove unused private class members#14026

Merged
graphite-app[bot] merged 1 commit intomainfrom
09-22-feat_minifier_remove_unused_private_class_members
Sep 24, 2025
Merged

feat(minifier): remove unused private class members#14026
graphite-app[bot] merged 1 commit intomainfrom
09-22-feat_minifier_remove_unused_private_class_members

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Sep 23, 2025

Compress

class C {
  #unused = 1;
  #used = 2;
  method() { return this.#used; }
}

to

class C {
  #used = 2;
  method() { return this.#used; }
}

.

The symbol usage is collected in the main traverse. The removal happens in exit_class_body. This way we don't need additional traverse.

@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Sep 23, 2025
Copy link
Member Author

sapphi-red commented Sep 23, 2025


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.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 23, 2025

CodSpeed Instrumentation Performance Report

Merging #14026 will not alter performance

Comparing 09-22-feat_minifier_remove_unused_private_class_members (aac45ef) with main (a05cb23)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (aac45ef) during the generation of this report, so a05cb23 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@sapphi-red sapphi-red force-pushed the 09-22-feat_minifier_remove_unused_private_class_members branch from c25331e to 3d5b891 Compare September 23, 2025 05:27
@sapphi-red sapphi-red marked this pull request as ready for review September 23, 2025 06:37
Copilot AI review requested due to automatic review settings September 23, 2025 06:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds optimization to remove unused private class members (fields, methods, and accessors) from JavaScript classes during minification. The implementation tracks private member usage during AST traversal and removes unused members during class body processing.

  • Adds tracking mechanism for private member usage across nested class scopes
  • Implements removal logic for unused private fields, methods, and accessor properties
  • Preserves members with side effects in their initializers

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
crates/oxc_minifier/src/state.rs Adds ClassSymbolsStack to track private member usage across class scopes
crates/oxc_minifier/src/peephole/remove_unused_private_members.rs Implements the core logic for removing unused private members with comprehensive tests
crates/oxc_minifier/src/peephole/mod.rs Integrates the optimization into the traversal pipeline
tasks/track_memory_allocations/allocs_minifier.snap Updates memory allocation snapshots

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sapphi-red sapphi-red requested a review from Boshen September 23, 2025 06:38
@sapphi-red sapphi-red force-pushed the 09-22-feat_minifier_remove_unused_private_class_members branch 2 times, most recently from 26abcd8 to caaa44b Compare September 23, 2025 13:26
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Sep 24, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 24, 2025

Merge activity

Compress
```js
class C {
  #unused = 1;
  #used = 2;
  method() { return this.#used; }
}
```
to
```js
class C {
  #used = 2;
  method() { return this.#used; }
}
```
.

The symbol usage is collected in the main traverse. The removal happens in `exit_class_body`. This way we don't need additional traverse.
@graphite-app graphite-app bot force-pushed the 09-22-feat_minifier_remove_unused_private_class_members branch from caaa44b to aac45ef Compare September 24, 2025 03:34
@graphite-app graphite-app bot merged commit aac45ef into main Sep 24, 2025
25 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 24, 2025
@graphite-app graphite-app bot deleted the 09-22-feat_minifier_remove_unused_private_class_members branch September 24, 2025 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants