Skip to content

Mutable fields, not structs? #37216

Closed
Closed

Description

Apologies if there's already an issue open for this already. I took a quick look but.

Many times when I define a mutable struct, but I know there's only one or two fields in it that will ever change, I feel slightly guilty. I suspect there must be optimizations that could become available if Julia knew which of the fields might change, and which might not. For example, in the following example, perhaps I know that b might change, but a will not.

mutable struct A
    a::Int
    b::Int
end

So I could imagine writing it like this instead:

struct A
    a::Int
    mutable b::Int
end

Of course, it's possible to make b a Ref, but perhaps the solution above seems a bit more general?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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