From: "byroot (Jean Boussier)" Date: 2021-09-14T06:48:01+00:00 Subject: [ruby-core:105247] [Ruby master Feature#18148] Marshal.load freeze option Issue #18148 has been updated by byroot (Jean Boussier). > When freeze:true is specified, only returned value from proc will be frozen? It could be either really, but I think the proc should be called with the objects already frozen, mostly to allow deserializing strings with `rb_interned_str...` > It would be helpful for us if you cloud add a simple code example for a feature proposal. Sure I'll add some. ---------------------------------------- Feature #18148: Marshal.load freeze option https://bugs.ruby-lang.org/issues/18148#change-93654 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal ---------------------------------------- ### Behavior If passed `freeze: true`, all the deserialized objects should be frozen, and if possible, strings should be deduped. This is similar to the `freeze` option recently added to `JSON` (https://github.com/flori/json/pull/447), `Psych` (https://github.com/ruby/psych/pull/414) and `MessagePack` (https://github.com/msgpack/msgpack-ruby/pull/194). ### Use cases This option is useful in many scenarios: - If the deserialized data is meant to stay on the heap for the lifetime of the program, the string deduplication reduce the memory overhead, and all objects being frozen improve copy on write and ensure that static data isn't accidentally mutated. - If the deserialized data is used in a memory cache or similar, deep freezing it protect against mutation and allow to return the value directly without first deep cloning it. - While not very performant, it can be used as a `deep_freeze` mechanism with `Marshal.load(Marshal.dump(object), freeze: true)`. -- https://bugs.ruby-lang.org/ Unsubscribe: