# Should Dry::Struct set immutable: true on Dry::Equalizer mixin?

**URL:** https://discourse.dry-rb.org/t/should-dry-struct-set-immutable-true-on-dry-equalizer-mixin/949
**Category:** Ideas
**Created:** [November 12, 2019, 6:43pm UTC](https://discourse.dry-rb.org/t/should-dry-struct-set-immutable-true-on-dry-equalizer-mixin/949 "2019-11-12T18:43:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![acdebaca](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@acdebaca](https://discourse.dry-rb.org/u/acdebaca)
#### Post date: [November 12, 2019, 6:43pm UTC](https://discourse.dry-rb.org/t/should-dry-struct-set-immutable-true-on-dry-equalizer-mixin/949/1 "2019-11-12T18:43:21Z")

</div>

Greetings!

dry-equalizer 0.3.0 includes [a change that adds a memoized hash method](https://github.com/dry-rb/dry-equalizer/commit/68f943d30aae54c0a3eea55c373a9f84d93b6386#diff-4462561a8c0d9638ec84227b8a535f4c). Is there any reason not to enable this feature on `Dry::Struct`?

E.g. [replace this](https://github.com/dry-rb/dry-struct/blob/master/lib/dry/struct.rb#L89):

`include Dry::Equalizer(: __attributes__ )`

with the following:

`include Dry::Equalizer(: __attributes__ , immutable: true)`

Might break code for anyone (ab)using `Dry::Struct` for mutable objects and expecting the `hash` method to recalculate accordingly. Seems like a remote possibility.

I have a recursive data structure (a tree) that I model with `Dry::Struct` subclass instances; by including the `Dry::Equalizer` module as above directly in my subclasses, the average invocation of `hash` dropped from 3.25 sec to under 20ms.

---

<div class="post-metadata">

### Author: ![flash-gordon](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/flash-gordon/32/494_2.png) [@flash-gordon](https://discourse.dry-rb.org/u/flash-gordon)
#### Post date: [November 14, 2019, 7:34am UTC](https://discourse.dry-rb.org/t/should-dry-struct-set-immutable-true-on-dry-equalizer-mixin/949/2 "2019-11-14T07:34:41Z")

</div>

Yes, this makes sense. I’ll add it as an option with `true` by default later this week. I plan to run it here and there for some time and cut a release some time next week.

---

<div class="post-metadata">

### Author: ![acdebaca](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@acdebaca](https://discourse.dry-rb.org/u/acdebaca)
#### Post date: [November 14, 2019, 7:55am UTC](https://discourse.dry-rb.org/t/should-dry-struct-set-immutable-true-on-dry-equalizer-mixin/949/3 "2019-11-14T07:55:27Z")

</div>

Awesome. Thanks for the response!
