Skip to content

The Error type should be smaller #21

Description

@Techcable

The problem / use case
Currently, processkit::Error is over 100 bytes. This bloats both direct users and types like vcs_core::Error which contain it indirectly. These large types frequently fire the clippy lints result_large_err and large_enum_variant. These clippy lints are both on by default; they aren't pedantic.

Errors are presumably on the cold path, so having large error types reduces the performance of the common case.

Proposed solution
Since the processkit::Error enum is public. It is not possible to fix this without a breaking change.
The largest variants only use stdlib types like String, Vec, and Duration.
We cannot shrink the size of these types even if we wanted to.

One option is to box these individual fields of the enum. This is a breaking change.

A more robust solution is to rename the current processkit::Error enum to something like ErrorReason, ErrorKind, or ErrorInfo. Then processkit::Error could hold a boxed reference to the kind. This is similar to the stdlib std::io::Error and std::io::ErrorKind distinction, although our "kind"/"reason"/"info" enum would hold more data than io::ErrorKind.

struct Error {
   reason: Box<ErrorReason>
}
impl Error {
  pub fn reason(&self) -> &ErrorReason {
    &self.reason
  }
}
enum ErrorReason {
    // all the same variants we currently have in Error
}

Alternatives considered
Leave as is, hurting performance and requiring clippy suppressions.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions