[Swift-devel] Swift crashing for runs with 1M calls

Yadu Nand yadudoc1729 at gmail.com
Mon Mar 11 15:36:25 CDT 2013


>> So, any loop large enough with a dependency on previous values could
>> trigger this error ? Throwing more memory into the system or giving more
>> time wouldn't help this, right ?
>
> Right. Though I was wrong about 2^n, it's O(n) instead, but still enough
> to cause a stack overflow.

Okay. Hmm.. so we could measure how much more loops we can afford
with more memory.

>> I'm also seeing swift hung, after I removed the dependency, probably a
>> different issue.
>> Here's what I see : http://pastebin.com/J9V3xyqU
>> I killed the process after 15 mins.
>
> Not sure what you mean by "removing dependency".

I just removed the dependency on array values filled in by previous threads.
instead of array[n] = array[n-1] + array[n-2], I went with array[n] = n*n;
So hang checker would determine that the threads of execution are independent,
right ?

>> > One solution may be to stop the hang checker when things get too big.
>> > That way it can still be useful for normal stuff.
>> >
>> > The hang checker's invocation here is unfortunate though. the assignment
>> > int range[] = [2:limit:1]; does the silly thing of actually creating an
>> > array with 1M elements (if you say foreach v in range..., that does not
>> > happen). It may be useful to change setFieldValue to do a simple
>> > reference assignment instead of copying the entire array, but that might
>> > not be easy given the way that assignment is implemented (i.e. not when
>> > the array is created).
>>
>> Did you mean to say that foreach v in [2:limit:1] would avoid having the
>> 1 million array elements created in range[] ? In what way would this
>> affect the execution of the script, make it faster ?
>
> That's right. Range returns a lazy array. Basically each element in the
> array is initialized when foreach tries to access it.
>
> The problem is in the array = range() assignment. The creation of 1M
> swift array data elements is slow. Slow enough to trigger the hang
> checker. At least that's my take on it.

Oh cool! The code without the range assignment, ran 1M loops.
1M   in 1m22.327s (I think this is a big improvement)
10M -> crashes with error (http://pastebin.com/bac6FEms)


-- 
Thanks and Regards,
Yadu Nand B



More information about the Swift-devel mailing list