-
-
Notifications
You must be signed in to change notification settings - Fork 475
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
refactor(config): reduce size by 350% using exact rule options #1876
Conversation
✅ Deploy Preview for biomejs canceled.
|
Parser conformance results onjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
crates/biome_cli/tests/snapshots/main_commands_rage/with_linter_configuration.snap
Show resolved
Hide resolved
c9920cc
to
7fc9963
Compare
7fc9963
to
ff29bef
Compare
CodSpeed Performance ReportMerging #1876 will not alter performanceComparing Summary
|
ac190df
to
e057bc5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff!
crates/biome_cli/tests/snapshots/main_commands_rage/with_linter_configuration.snap
Show resolved
Hide resolved
Good suggestion! Unfortunately this requires a However, one snapshot ( I think it is fine to keep the current caveat because it is unlikely that someone uses |
Summary
Part of #1263.
This should also help for #1795.
This PR reduces by 352% (from 4016 bytes to 1140 bytes) the memory usage of
biome.json
.Most of the memory usage comes from the
RuleConfiguration
type (16 bytes) that is present for every rule.RuleConfiguration
is an enum with two variants, thus it took the size of its biggest variant:RuleWithOptions
.Most of the rules have no options, so this is just a waste of memory.
I managed to reduce the size of
RuleWithOptions
to only 1 byte for a rule without options.This reduces the size of
RuleConfiguration
to 2 bytes :)To do that, I added a type parameter to
RuleConfiguration
andRuleWithOptions
.This type parameter is set to the Options type of the rule. Most of the rule has
Rule::Options
set to()
.Rules with options took a variable amount of memory depending on the memory layout of their options.
I used the same trick as my previous PR (#1283) to ensure a maximum usage of 16 bytes: I wrapped the
Options
type in aBox
when its size is larger than 16 (this is the case for 3 rules).A nice side effect is that we get exact JSON schema.
We now generate an
options.rs
file inbiome_js_analyze
andbiome_json_analyze
that exports the options for the rules.I had to make the rules public to satisfy the Rust compiler: it reported the use of a crate-scoped type in the public interface. Unfortunately disabling the Clippy check is not enough: the compiler still complained.
I also had to fix a bug in our deserializable derive macro that handled wrongly constrained generics.
Test Plan
CI should pass.