-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Truffle] SystemStackError in String#[] #4394
Comments
Here is a repro for length = 10*1024*1024
buf = " " * length
length.times { |i|
buf[i] = "0"
}
p buf[0] and the backtrace: $ jth ruby --graal 16bug2.rb
.../jruby-dev/truffle/src/main/ruby/core/string_mirror.rb:65:in `splice': stack level too deep (SystemStackError)
from .../jruby-dev/truffle/src/main/ruby/core/string.rb:1308:in `[]='
from 16bug2.rb:4:in `block in <main>'
from 16bug2.rb:3:in `times'
from 16bug2.rb:3:in `<main>'
|
I'll mention this old pull request since it might have been trying to solve a similar issue: |
This is unfortunately a pathological case for ropes currently. Replacing each byte or character is problematic because the ropes themselves are read-only. Preallocating really has no additional benefit because you're not going to update bytes in a fixed buffer. But, if you really just wanted 35 MB of "0", then I'll see if I can find a way to make this work better. |
At first I do not care so much about performance, but at least it should not stack overflow. The first snippet only does appends, so that one should not be so bad with ropes, isn't it? |
It looks like 8abc05a solves both cases, thank you! |
I was looking at running my solution for http://adventofcode.com/2016/day/16 with JRuby+Truffle, but it seems it does not like to look in the 35MB String.
The full code is at https://gist.github.com/eregon/fdf20a89763e87045cbefb9309cef76c
I also tried a variant by pre-allocating a String and modifying it, but then
[]=
died in stack overflow.Here is a small repro:
The text was updated successfully, but these errors were encountered: