Firefox、Chrome、Safari、IE 等的 js 递归限制是多少?
我有一些使用相当深的递归的Javascript代码,我想找出各种浏览器中的递归限制是什么(即发生“太多递归”错误的点)。
有人有这方面的可靠数字吗?按版本划分?
I've got some Javascript code which uses fairly deep recursion and I'd like to find out what the recursion limits in the various browsers are (i.e. the point at which the error "too much recursion" will happen).
Anyone have any solid numbers on this, by version?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Nicholas C. Zakas 在他的博客中写道:
还有一些关于不同浏览器和操作系统的更多数据 此处。
我创建了一个 Browserscope 测试来获取更多数据。 请在此处运行。
2019 年 2 月更新:
上述结果现已过时,但浏览器范围结果已更新:
Nicholas C. Zakas writes in his blog:
There's some more data on different browsers and OSs here.
I've created a Browserscope test to get more data. Please run it here.
Update Feb 2019:
The results above are now obsolete, but the browserscope results are updated :
要添加此处的答案,这也可能取决于递归中涉及的函数。例如,只需向函数添加一些参数就可以更改结果:
给我 20923,但
报告 13949(在 Chromium 39 的控制台中测试)。 Firefox 34 分别给出 25085 和 13572。
在零参数
inc()
的主体周围添加一个 try/catch 块可以在 Chromium 中提供 11413 个帧,在 Firefox 中提供 13161 个帧。同时使用 3 个参数和 try/catch 块,Chrome 中为 8967,Firefox 中为 7517。我从中得出的结论是,在浏览器中接近堆栈深度工作的应用程序可能只能根据与应用程序中使用的函数类似的函数的经验测量来计算出这一点。
To add to the answers here, this can depend on the functions involved in the recursion, as well. For example, just adding a few parameters to the function can change the result:
gives me 20923, but
reports 13949 (tested in the console in Chromium 39). Firefox 34 gives 25085 and 13572, respectively.
Adding a try/catch block around the body of the zero-argument
inc()
gives 11413 frames in Chromium and 13161 in Firefox. With both 3 arguments and the try/catch block, 8967 in Chrome and 7517 in Firefox.My takeaway from this is that an application that works near the stack depth in a browser can probably only figure this out based on empirical measurements of functions resembling those used in the app.