Skip to content
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

Clippy complains about tame_index::Error being very large in size #31

Closed
Shnatsel opened this issue Sep 25, 2023 · 1 comment · Fixed by #32
Closed

Clippy complains about tame_index::Error being very large in size #31

Shnatsel opened this issue Sep 25, 2023 · 1 comment · Fixed by #32
Labels
bug Something isn't working

Comments

@Shnatsel
Copy link
Contributor

Shnatsel commented Sep 25, 2023

Describe the bug
Clippy complains about tame_index::Error being very large:

 error: the `Err`-variant returned from this function is very large
Error:   --> rustsec/src/cached_index.rs:77:10
   |
77 |     ) -> Result<Self, tame_index::Error> {
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes
   |
   = help: try reducing the size of `tame_index::Error`, for example by boxing large elements or replacing it with `Box<tame_index::Error>`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err

For structs of over 128 bytes passed by value LLVM invokes memcpy(), so propagating the error up the call stack with ? over multiple functions involves multiple memcpy() calls. This is rather slow, although it is unlikely to be a problem for tame-index in practice since most of the time is spent waiting on the network anyway.

To Reproduce
cargo clippy

Device:
Clippy 1.67.0 on Linux x86_64. Doesn't happen in later Clippy versions, which is peculiar.

@Jake-Shadle
Copy link
Member

That error is incorrect, the largest size is 120 bytes, so maybe that old version of clippy was calculating it incorrectly.

print-type-size type: `error::Error`: 120 bytes, alignment: 8 bytes
print-type-size     variant `Git`: 120 bytes
print-type-size         field `.0`: 120 bytes
print-type-size     variant `Toml`: 96 bytes
print-type-size         field `.0`: 96 bytes
print-type-size     variant `Local`: 56 bytes
print-type-size         field `.0`: 56 bytes
print-type-size     variant `IoPath`: 32 bytes
print-type-size         field `.0`: 8 bytes
print-type-size         field `.1`: 24 bytes
print-type-size     variant `InvalidUrl`: 32 bytes
print-type-size         field `.0`: 32 bytes
print-type-size     variant `NonUtf8Path`: 24 bytes
print-type-size         field `.0`: 24 bytes
print-type-size     variant `InvalidKrateName`: 24 bytes
print-type-size         field `.0`: 24 bytes
print-type-size     variant `Http`: 24 bytes
print-type-size         field `.0`: 24 bytes
print-type-size     variant `Io`: 8 bytes
print-type-size         field `.0`: 8 bytes
print-type-size     variant `Json`: 8 bytes
print-type-size         field `.0`: 8 bytes
print-type-size     variant `Semver`: 8 bytes
print-type-size         field `.0`: 8 bytes
print-type-size     variant `Cache`: 1 bytes
print-type-size         field `.0`: 1 bytes
print-type-size     variant `NoCrateVersions`: 0 bytes

But Git is still larger than most of the others by a wide margin. I'll slim it down, again.

Jake-Shadle added a commit that referenced this issue Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants