Does javascript cause serious recursion?

I wrote javascript to emulate the WPF DockPanel Layout behavior in HTML using javascript.

Now I run into performance issues when I start pasting these panels at recursion level 10. Oddly enough, this is nothing more than regular recursion, and at the deepest level, this function ends between 0.2 and 2 ms.

Profiler image

Now either I have a ghost performance loss, or is there a huge cost when calling recursion for javascript? I hope one of you knows.

If there is value, then the obvious solution would be a reversal of recursion, which would be rather sad.

I read a SO recursive function calling in JavaScript about this, but does it really mean that I may have to take recursiondepth n = functioncost * (10 ^ (n-1)) for each recursion depth will I go?

Also, this (which disproves the idea of ​​recursion more slowly than iteration) SO - Is it faster than recursion, or less prone to stack overflows?

And this Programmers: Performance: recursion versus iteration in Javascript , which speaks for iteration faster than recursion, 4 times (sigh ...)

This is a general JS browser independent issue. If you know about this, be it slow in one, but fast in the other, that information would also be welcome. I assumed that it would be the same thing.

Visitor Wrap Information: The effects of recursion and iteration are very important. The iteration generally wins.

  • FF30 Factor: 5 ~
  • Chrome factor 36: 40 ~
  • Native IE8 WinXP Factor: 10 ~
0
source share
1 answer

Yes, recursion has a very big impact on JavaScript performance, always avoids it, uses only an iterative approach

A simple example of a fibonacci function (recursion versus loop):

http://jsperf.com/fibonacci-recursive-or-iterative/4

Another example I wrote some time ago (object navigation):

http://jsperf.com/object-navigation

var a = { b: { c: 'd' } }; find(a, 'b/c'); // => 'd' 

OP-Test: http://jsperf.com/iterative-vs-recursive-method-invocation/3

+5
source

Source: https://habr.com/ru/post/1236752/


All Articles