dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
415 stars 108 forks source link

Deduplicate locale tokens #399

Closed casperisfine closed 2 years ago

casperisfine commented 2 years ago
   5.02 kB      57  "%<locale>s.dry_schema.rules.%<name>s"
                57  dry-schema-1.8.0/lib/dry/schema/messages/yaml.rb:43

   5.02 kB      57  "%<locale>s.dry_schema.errors"
                57  dry-schema-1.8.0/lib/dry/schema/messages/yaml.rb:41
solnic commented 2 years ago

Thanks, could you tell me what this is actually doing though?

casperisfine commented 2 years ago

String#-@ interns the string.

As shown heap-profiler, if you instantiate X schemas, you end up with X copies of these two strings.

By using String#-@ we deduplicate these strings so that all schemas point to the same (frozen) one, saving about 10KiB (in this case).