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

Permit @auto_hash_equals cached=true with mutable struct types. #34

Open
gafter opened this issue Jun 2, 2023 · 1 comment
Open

Permit @auto_hash_equals cached=true with mutable struct types. #34

gafter opened this issue Jun 2, 2023 · 1 comment

Comments

@gafter
Copy link
Member

gafter commented Jun 2, 2023

Either

  1. Require that all declared fields are const, or
  2. Add const to each declared field (with a warning?) if not already declared so.

The advantage of doing this is that we get both an efficient hash code and an efficient equality (because of the === shortcut)

const on a field is only available in Julia 1.8 and later.

@NHDaly
Copy link
Member

NHDaly commented Jun 29, 2023

(The disadvantage is that every field access has to go to the heap. With an immutable struct, fields can be pulled onto the stack or into registers, which can improve the performance of a function that spends a lot of time with those fields. If you're just hopping off to the next child in a tree or something, this probably matters less.)

@gafter gafter changed the title Permit @auto_hash_equals_cached with mutable struct types. Permit @auto_hash_equals cached=true with mutable struct types. Aug 18, 2023
@gafter gafter transferred this issue from JuliaServices/AutoHashEqualsCached.jl Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants