Skip to content

Replace backtrace fields on wrapper error types with methods #2251

@data-sync-user

Description

@data-sync-user

We are doing a lot of cloneing of the backtraces we generate in inner error types when converting Kinds into their wrapper types in From impls. If this proves to have substantial performance implications, we should replace the backtrace fields on the outer types with methods that return a reference to the backtrace fields on the wrapped “kind” types.

For example, we might have a type ApiErrorKind that looks something like

struct ApiErrorKind {
    ...
    backtrace: Backtrace,
    ...
}

and a wrapper type ApiError that looks like

struct ApiError {
    ...
    kind: ApiErrorKind,
    backtrace: Backtrace,
    ...
}

where the backtrace field in ApiError is a clone of the backtrace field in ApiErrorKind. Instead of cloning that field, we could implement a method on ApiError like so:

impl ApiError {
    fn backtrace(&self) -> &Backtrace {
        &self.kind.backtrace
    }
}

┆Issue is synchronized with this Jira Task

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions