Skip to content

Commit

Permalink
Optimize the #[must_use] lint queries by improving filtering. (#286)
Browse files Browse the repository at this point in the history
Most items are not `#[must_use]`. By moving the more-selective branch of the query (the `current` one that looks for `#[must_use]`), the query will evaluate fewer items because it will discard more of them earlier in the process.

The speedup is approximately a factor of 1600-2000x when measured on a particularly large crate: `aws-sdk-ec2`
/~https://github.com/awslabs/aws-sdk-rust/tree/main/sdk/ec2 

Running just the 4 affected lints on that crate:
- Before: 401-413s total scan time
- After: 0.21-0.25s total scan time

The numbers only include lint execution time, excluding things such as the time needed to build the rustdoc JSON.

This is an optimization that requires knowing the underlying shape of the dataset being queried, so it's not something that Trustfall could have applied automatically without access to statistics.
  • Loading branch information
obi1kenobi authored Jan 11, 2023
1 parent 06026c5 commit cf1e270
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 48 deletions.
24 changes: 12 additions & 12 deletions src/lints/enum_must_use_added.ron
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@ SemverQuery(
query: r#"
{
CrateDiff {
baseline {
current {
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
visibility_limit @filter(op: "=", value: ["$public"])
name @tag @output
importable_path {
path @tag @output
}
attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
attribute {
new_attr: raw_attribute @output
content {
base @filter(op: "=", value: ["$must_use"])
}
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
current {
baseline {
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @filter(op: "=", value: ["%name"])
importable_path {
path @filter(op: "=", value: ["%path"])
}
attribute {
new_attr: raw_attribute @output
attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$must_use"])
}
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/lints/function_must_use_added.ron
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@ SemverQuery(
query: r#"
{
CrateDiff {
baseline {
current {
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"]) @output
visibility_limit @filter(op: "=", value: ["$public"])
name @tag @output
importable_path {
path @tag @output
}
attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
attribute {
new_attr: raw_attribute @output
content {
base @filter(op: "=", value: ["$must_use"])
}
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
current {
baseline {
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @filter(op: "=", value: ["%name"])
importable_path {
path @filter(op: "=", value: ["%path"])
}
attribute {
new_attr: raw_attribute @output
attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$must_use"])
}
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/lints/struct_must_use_added.ron
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@ SemverQuery(
query: r#"
{
CrateDiff {
baseline {
current {
item {
... on Struct {
visibility_limit @filter(op: "=", value: ["$public"]) @output
visibility_limit @filter(op: "=", value: ["$public"])
name @tag @output
importable_path {
path @tag @output
}
attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
attribute {
new_attr: raw_attribute @output
content {
base @filter(op: "=", value: ["$must_use"])
}
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
current {
baseline {
item {
... on Struct {
visibility_limit @filter(op: "=", value: ["$public"])
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @filter(op: "=", value: ["%name"])
importable_path {
path @filter(op: "=", value: ["%path"])
}
attribute {
new_attr: raw_attribute @output
attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$must_use"])
}
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/lints/trait_must_use_added.ron
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@ SemverQuery(
query: r#"
{
CrateDiff {
baseline {
current {
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"]) @output
visibility_limit @filter(op: "=", value: ["$public"])
name @tag @output
importable_path {
path @tag @output
}
attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
attribute {
new_attr: raw_attribute @output
content {
base @filter(op: "=", value: ["$must_use"])
}
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
current {
baseline {
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"])
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @filter(op: "=", value: ["%name"])
importable_path {
path @filter(op: "=", value: ["%path"])
}
attribute {
new_attr: raw_attribute @output
attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$must_use"])
}
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
Expand Down

0 comments on commit cf1e270

Please sign in to comment.