Project

General

Profile

Bug #5719

Hash::[] can't handle 100000+ args

Added by qrush (Nick Quaranto) over 5 years ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:41511]

Description

I couldn't pin down an exact size for when/how this occurs, but I have code that was creating hashes just fine with Hash::[] with 300k+ arguments.

irb(main):056:0> (0...140000).map { |n| [:a, n] }.tap { |a| Hash[*a] }.size
SystemStackError: stack level too deep
from /Users/qrush/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/irb/workspace.rb:80
Maybe IRB bug!
irb(main):057:0> (0...130000).map { |n| [:a, n] }.tap { |a| Hash[*a] }.size
=> 130000


Related issues

Related to Ruby trunk - Bug #4040: SystemStackError with Hash[*a] for Large _a_Assigned

History

#1 [ruby-core:41512] Updated by iterology (John Glass) over 5 years ago

I was able to duplicate this issue with the above code in 1.9.2-p290 It didn't matter if I ran it through IRB or from the command line.

#2 [ruby-core:41515] Updated by gabrielg (Gabriel Gironda) over 5 years ago

It looks to be a variable argument length thing, not a Hash thing in particular.

https://gist.github.com/5037bf83d28c2c119c44

Edit: Not just variable argument length. Ruby just won't have any of your guff if you intend on passing any method a very large number of arguments.

https://gist.github.com/d259449ff7bedef92c2e

This is reasonable, I think.

#3 [ruby-core:41513] Updated by matz (Yukihiro Matsumoto) over 5 years ago

  • ruby -v changed from 1.9.3-p0 to -

Hi,

In message "Re: [ruby-trunk - Bug #5719][Open] Hash::[] can't handle 100000+ args"
on Wed, 7 Dec 2011 11:30:44 +0900, Nick Quaranto nick@quaran.to writes:

|I couldn't pin down an exact size for when/how this occurs, but I have code that was creating hashes just fine with Hash::[] with 300k+ arguments.

Unfortunately we are living in the very restricted real world. ;-)

                        matz.

#4 [ruby-core:41516] Updated by deepfryed (Bharanee Rathna) over 5 years ago

i shall give you four hints: stack, heap, push, pop

ruby's behavior is expected.

you can pass Hash::[] an array instead i think.

Hash[[[:a, 1], [:b, 2]]] #=> {:a=>1, :b=>2}

#5 [ruby-core:41519] Updated by duerst (Martin Dürst) over 5 years ago

This is related to http://redmine.ruby-lang.org/issues/982. In terms of what needs to be done, it may even be "the same" bug, although 982 is about a very long array literal, and this is about a very long array created by a splash. At http://redmine.ruby-lang.org/issues/982, Koichi Sasada said 「すみません,1.9.3 の後の課題とさせて下さい.」, i.e. "sorry, but let's deal with this after 1.9.3". So now may be a good time :-).

#6 [ruby-core:42887] Updated by ko1 (Koichi Sasada) over 5 years ago

  • Category set to core
  • Assignee set to ko1 (Koichi Sasada)
  • Target version set to 2.0.0

#7 [ruby-core:42886] Updated by ko1 (Koichi Sasada) over 5 years ago

(2011/12/07 14:26), Martin Dürst wrote:

This is related to http://redmine.ruby-lang.org/issues/982. In terms of what needs to be done, it may even be "the same" bug, although 982 is about a very long array literal, and this is about a very long array created by a splash. At http://redmine.ruby-lang.org/issues/982, Koichi Sasada said 「すみません,1.9.3 の後の課題とさせて下さい.」, i.e. "sorry, but let's deal with this after 1.9.3". So now may be a good time :-).

Thank you. It is correct. And there are no progress on it. Sorry.
Should we solve this issue as high priority?

--
// SASADA Koichi at atdot dot net

#8 [ruby-core:43014] Updated by duerst (Martin Dürst) over 5 years ago

Hello Koichi,

On 2012/02/25 13:34, SASADA Koichi wrote:

(2011/12/07 14:26), Martin Dürst wrote:

This is related to http://redmine.ruby-lang.org/issues/982. In terms of what needs to be done, it may even be "the same" bug, although 982 is about a very long array literal, and this is about a very long array created by a splash. At http://redmine.ruby-lang.org/issues/982, Koichi Sasada said 「すみません,1.9.3 の後の課題とさせて下さい.」, i.e. "sorry, but let's deal with this after 1.9.3". So now may be a good time :-).

Thank you. It is correct.

Thanks for the confirmation.

And there are no progress on it. Sorry.
Should we solve this issue as high priority?

I'm not sure "high priority" is the right word. It's always possible to
work around it.

But it's highly annoying when somebody hits this issue. It's also highly
counterintuitive: Ruby deals with Arrays of any size automatically, but
then can't handle the same size in a literal.

So I very much think that 2.0 is a good point to get rid of this
problem. I'm not sure what's involved in fixing it, but if there's
something I can contribute, I'll be glad to help.

Regards, Martin.

#9 Updated by shyouhei (Shyouhei Urabe) over 5 years ago

  • Status changed from Open to Assigned

#10 [ruby-core:50132] Updated by ko1 (Koichi Sasada) over 4 years ago

  • Target version changed from 2.0.0 to next minor

#11 Updated by ko1 (Koichi Sasada) 7 months ago

  • Related to Bug #4040: SystemStackError with Hash[*a] for Large _a_ added

#12 [ruby-core:79353] Updated by ko1 (Koichi Sasada) 7 months ago

  • Status changed from Assigned to Closed

See #4040 and close this ticket.

Also available in: Atom PDF