Bug 13289 - Call stack size limit too aggressive for functional programming (Maximum call stack size exceeded)
Summary: Call stack size limit too aggressive for functional programming (Maximum call...
Status: RESOLVED DUPLICATE of bug 4045
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 419.x
Hardware: Mac (PowerPC) OS X 10.4
: P2 Major
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-05 12:25 PDT by Chris van Rensburg
Modified: 2007-04-05 14:10 PDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris van Rensburg 2007-04-05 12:25:34 PDT
We recently encountered a "Maximum call stack size exceeded" error in Safari with our online AJAX calendar design tool (http://www.zazzle.com/design/calendar).

The first culprit one tends to suspect in a case like this is an infinite recursion. However, after heavily scrutinizing and tracing through the code, double checking, triple checking, and quadruple checking, it turned out that a finite chain of recursion triggered the "Maximum call stack size exceeded" error. The code in question was performing an iteration that could possibly involve asynchronous processes, of the form...

function _processElementsAsync (_elements) {
	var
		_elementsLength = _elements.length,
		_elementNo = -1
	;
	function _handleNextElement () {
		_elementNo++;
		if (_elementNo < _elementsLength) {
			_someAsyncFunction (_elements [_elementNo],_handleNextElement /* the continuation function */);
		} else {
			// completion code
		}
	}
	_handleNextElement ();
}

AJAX development inevitably involves more functional style programming, with more anonymous functions / lambda closures. This has effects on the patterns of memory usage. The more extensively one utilizes asynchronous coding, the more closures one tends to introduce. The application (and code) in question worked without a hitch in IE6 and FF2, but produced the "Maximum call stack size exceeded" error in Safari 2.04 (419.3).

An Internet search reveals a number of cutting edge JS / Web 2.0 developers encountering this issue. Since JavaScript's functional programming facilities are being utilized more and more in RIA's, more state memory is going to find its way into the call stack rather than in deliberately created objects. In the light of this, it seems Safari's configured limit on the call stack size is a little bit too aggressive and may over time snag (and frustrate) more and more serious / hard core Web application developers.
Comment 1 David Kilzer (:ddkilzer) 2007-04-05 14:10:40 PDT
Hi Chris, is there a reason you're filing this again?  It's identical to Bug 13284.

The issue is well-known by the Safari team, as indicated by the fact that there is a Radar bug for it.



*** This bug has been marked as a duplicate of 4045 ***