spacedriveapp / spacedrive

Spacedrive is an open source cross-platform file explorer, powered by a virtual distributed filesystem written in Rust.
https://spacedrive.com
GNU Affero General Public License v3.0
31.5k stars 930 forks source link

Box heavy data inside enum #2466

Closed matheus-consoli closed 4 months ago

matheus-consoli commented 4 months ago

Clippy warns about the size of these two variants being way too big compared to their siblings, so, as a potential performance improvement, it's better to Box them, which makes the enum lighter.

vercel[bot] commented 4 months ago

@matheus-consoli is attempting to deploy a commit to the Spacedrive Team on Vercel.

A member of the Team first needs to authorize it.

matheus-consoli commented 4 months ago

for contrast, the lint messages:

warning: large size difference between variants
  --> core/src/api/locations.rs:38:1
   |
38 | /   pub enum ExplorerItem {
39 | | /     Path {
40 | | |         // provide the frontend with the thumbnail key explicitly
41 | | |         thumbnail: Option<ThumbnailKey>,
42 | | |         // this tells the frontend if a thumbnail actually exists or not
...  | |
45 | | |         item: file_path_with_object::Data,
46 | | |     },
   | | |_____- the largest variant contains at least 641 bytes
47 | | /     Object {
48 | | |         thumbnail: Option<ThumbnailKey>,
49 | | |         has_created_thumbnail: bool,
50 | | |         item: object_with_file_paths::Data,
51 | | |     },
   | | |_____- the second-largest variant contains at least 161 bytes
...  |
66 | |       },
67 | |   }
   | |___^ the entire enum is at least 0 bytes
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
   = note: `#[warn(clippy::large_enum_variant)]` on by default
help: consider boxing the large fields to reduce the total size of the enum
   |
45 |         item: Box<file_path_with_object::Data>,
   |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: large size difference between variants
   --> core/crates/heavy-lifting/src/file_identifier/tasks/extract_file_metadata.rs:106:3
    |
106 | /         enum StreamMessage {
107 | |             Processed(Uuid, Result<FileMetadata, FileIOError>),
    | |             -------------------------------------------------- the largest variant contains at least 224 bytes
108 | |             Interrupt(InterruptionKind),
    | |             --------------------------- the second-largest variant contains at least 1 bytes
109 | |         }
    | |_________^ the entire enum is at least 224 bytes