Project

General

Profile

Actions

Feature #7429

closed

Provide options for core collections to customize behavior

Added by headius (Charles Nutter) about 12 years ago. Updated about 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:50043]

Description

Many folks know that Matz is a fan of having a few classes that handle a wide range of behavior. For this reason, I think we're unlikely to get a set of parallelism-safe collections added to Ruby. I propose an alternative that would allow parallel-executing implementations to offer concurrency-friendly versions without impact to any code.

I would like to see a way to pass in an options hash to the .new construction of at least Hash and Array. For example:

Create a hash that is concurrenct-safe, resizes when density is > 3 keys per bucket,

and sets initial bucket count to 60

hsh = Hash.new(concurrent: true, density: 3, size: 60)

Similar for Array:

ary = Array.new(concurrent: true, size: 100)

Options like density and size map directly to current implementation details of Hash and Array that are sometimes not accessible (you can't change the load factor for Hash, for example). Options like concurrent could be noops on MRI but would allow other implementations to provide safe versions of the collections behind the scenes.

I know it may be too late for 2.0.0, but we implementers of parallel-executing Rubies feel the pain of thread-unsafe core structures every day. I think the ability to get thread-safe collections in Ruby core would go a long way toward dispelling the myth that Ruby is bad for concurrent application programming.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0