refactor(oxfmt): Use Box<FormatOptions> for ResolvedOptions#17772
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
Box<FormatOptions> for ResolvedOptions
There was a problem hiding this comment.
Pull request overview
This PR refactors the ResolvedOptions enum by boxing the FormatOptions field to reduce the overall size of the enum. This is a standard Rust optimization to prevent one large variant from inflating the size of all enum variants.
Key Changes:
- Changed
format_options: FormatOptionstoformat_options: Box<FormatOptions>in theResolvedOptions::OxcFormattervariant - Updated creation site to wrap
FormatOptionsin aBox - Updated usage site to dereference the boxed value when passing to the formatter
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/oxfmt/src/core/config.rs | Changed field type to Box<FormatOptions> and wrapped the value in Box::new() when constructing the enum variant |
| apps/oxfmt/src/core/format.rs | Dereferenced the boxed FormatOptions when passing it to format_by_oxc_formatter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
Preparation for #17576 ``` error: large size difference between variants --> apps/oxfmt/src/core/config.rs:51:1 | 51 | / pub enum ResolvedOptions { 52 | | /// For JS/TS files formatted by oxc_formatter. 53 | | / OxcFormatter { 54 | | | format_options: FormatOptions, 55 | | | /// For embedded language formatting (e.g., CSS in template literals) 56 | | | external_options: Value, 57 | | | insert_final_newline: bool, 58 | | | }, | | |_____- the largest variant contains at least 281 bytes ... | 66 | | / ExternalFormatterPackageJson { 67 | | | external_options: Value, 68 | | | sort_package_json: Option<sort_package_json::SortOptions>, 69 | | | insert_final_newline: bool, 70 | | | }, | | |_____- the second-largest variant contains at least 75 bytes 71 | | } | |___^ the entire enum is at least 288 bytes | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#large_enum_variant = note: `-D clippy::large-enum-variant` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum | 54 - format_options: FormatOptions, 54 + format_options: Box<FormatOptions>, | ```
35cbfd9 to
e9f1a43
Compare

Preparation for #17576