[#105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` — "byroot (Jean Boussier)" <noreply@...>
SXNzdWUgIzE4MjI4IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGJ5cm9vdCAoSmVhbiBCb3Vzc2llciku
11 messages
2021/09/27
[ruby-core:105240] [Ruby master Feature#18148] Marshal.load freeze option
From:
"ko1 (Koichi Sasada)" <noreply@...>
Date:
2021-09-14 04:42:32 UTC
List:
ruby-core #105240
Issue #18148 has been updated by ko1 (Koichi Sasada).
`Marshal.load()` accepts `proc` which can manipulate the loaded object:
```ruby
str = Marshal.dump(["a", 1, 10 ** 10, 1.0, :foo])
p Marshal.load(str, proc {|obj| [obj]})
#=> [[["a"], [1], [10000000000], [1.0], [:foo]]]
```
When `freeze:true` is specified, only returned value from proc will be frozen?
----------------------------------------
Feature #18148: Marshal.load freeze option
https://bugs.ruby-lang.org/issues/18148#change-93647
* 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: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>