prisma / quaint

SQL Query AST and Visitor for Rust
Apache License 2.0
582 stars 62 forks source link

ExpressionKind members have large size differences #200

Closed yoshuawuyts closed 3 years ago

yoshuawuyts commented 4 years ago

https://github.com/prisma/quaint/blob/95be46502571c425642c1006d8c40b8d39f5bfa8/src/ast/expression.rs#L170 and https://github.com/prisma/quaint/blob/fa99f5353bb6c225872f6b35546dd6b54bca6b8f/src/ast/table.rs#L22 are marked by clippy as 500 bytes, with the second-largest member being 40 bytes. Adding an intermediate box will likely help improve allocations / performance.

You can get this output by running:

$ cargo +nightly clippy

Thanks!

Output

warning: large size difference between variants
   --> src\ast\expression.rs:170:5
    |
170 |     Function(Function<'a>),
    |     ^^^^^^^^^^^^^^^^^^^^^^ this variant is 536 bytes
    |
    = note: `#[warn(clippy::large_enum_variant)]` on by default
note: and the second-largest variant is 40 bytes:
   --> src\ast\expression.rs:162:5
    |
162 |     RawValue(Raw<'a>),
    |     ^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
    |
170 |     Function(Box<Function<'a>>),
    |              ^^^^^^^^^^^^^^^^^

warning: large size difference between variants
  --> src\ast\table.rs:22:5
   |
22 |     Query(Select<'a>),
   |     ^^^^^^^^^^^^^^^^^ this variant is 296 bytes
   |
note: and the second-largest variant is 32 bytes:
  --> src\ast\table.rs:21:5
   |
21 |     Table(Cow<'a, str>),
   |     ^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
   |
22 |     Query(Box<Select<'a>>),
   |           ^^^^^^^^^^^^^^^