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

Mihael Hategan hategan at mcs.anl.gov
Mon Mar 11 13:32:48 CDT 2013


On Mon, 2013-03-11 at 20:21 +0530, Yadu Nand wrote:
> Hi Mihael,
> 
> This kind of information helps a lot.
> 
> > Yeah, the algorithm for finding loops is recursive. Since it has to deal
> > with 1M threads, it does fail. The code may not be recursive, but the
> > dependency is, so when the hang checker builds the dependency graph, it
> > will essentially try to build a graph that tracks where, say,
> > array[1000000] is. The complexity of that  is 2^n in this case, so,
> > yeah...
> 
> 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.

> 
> 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".

> 
> > 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.

Mihael





More information about the Swift-devel mailing list