Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28507

Re: Recursive function to find a node in the DOM

From "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it>
Newsgroups comp.lang.javascript
Subject Re: Recursive function to find a node in the DOM
Date 2015-08-08 01:21 +0200
Organization A noiseless patient Spider
Message-ID <mq3el5$dst$1@dont-email.me> (permalink)
References (5 earlier) <molf6c$2l1$1@dont-email.me> <1516357.lIjpcpmlPf@PointedEars.de> <4be984b1-7744-4271-acd8-a6a625977504@googlegroups.com> <mpv4ml$blj$1@dont-email.me> <1443069.sYRfn84SoE@PointedEars.de>

Show all headers | View raw


Il 08/06/2015 08:15 PM, Thomas 'PointedEars' Lahn ha scritto:
> danca (Daniele Campagna) wrote:
>
>> I copy/paste the following paragraph, extracted from a mail I sent
>> someone, on the subject:
>>
>> ----
>> But: one last consideration about the risk to crash due to wild increase
>> of the call stack.
>> You seems to think that if a document has a zillion nodes, the recursive
>> function will create a zillion of calls and subsequently a stack of a
>> zillion elements. It is not the case. What really matter is how deep is
>> a nested node from the starting node, because the algorythm calls itself
>> only to go to the next child node, but returns (and decreases the call
>> stack) when the current branch of the tree ends!!
>>
>> So I really don't think that a DOM can have a node nested more than,
>> say, a few dozen of levels, and this is the maximum amount the stack
>> will reach!
>> ----
>
> You know very well that I have replied to your e-mail and you have agreed
> that your argument was not sound.  I told you that I did not make the
> assumption you insuated there, at all.  In fact, you told me you had used
> your script on a large document and it failed; if not because of stack
> overflow, because of something else that you could not determine at the
> time – meaning you could not handle the complexity of the approach.  Now,
> two weeks later you are showing off here as if nothing happened.
>

Fairly correct, apart the point in which I "agreed that my argument was 
not sound".

> All this tells me that you are not trustworthy, and that I have wasted my
> time with you after all.

I don't see any problem in my reporting what *I* wrote you. Someone 
other could decide to comment, or not, and that comment could be in 
agreement with yours, or maybe not. I did not report what *you* answered 
me because I don't want feed flames or whatever, and moreover I don't 
think it would be polite. But I don't see any problem in just reporting 
that. Scott expressed some doubt about the memory consumption problem, 
and some appreciation for the recursive approach in programming, not to 
say the sound explanation about the passing of parameters in ECMAscript. 
It's quite obvious he's not a Sunday programmer. I just repeated my 
argument to him, because I don't think that what has been said by you is 
to be considered definitive. I simply don't agree completely with you, 
or, to be more precise, the assumptions you made don't apply to my 
particular circumstances, so I'm wondering if I can safely ignore the 
risks you cite, *in my case*.

Anyway, here is the copy of my answer:

//-------------------------------
But, as per premises, I am not writing a library for general purposes 
[nor I would be able to, at present time].
The last "reality check" I had, a browser was eating some 200 Mb of 
memory, so I maintain that a recursive function exploring the DOM hardly 
can crash for memory consumption reasons.

BTW I tested it on a quite large (for my standards!) page downloaded 
from Internet and modified in order to: 1)add my recursive function, 2) 
give a name to an arbitrary element and 3) put a button to call the 
function.
This is the report (from Mozilla) for the page weight:


	Size 	Uncompressed Size
21 Documents 	32 KB 	212 KB
23 Images 	19 KB 	19 KB
0 Objects 	
	
43 Scripts 	225 KB 	1786 KB
2 Style Sheets 	21 KB 	54 KB
89 Files 	297 KB 	2070 KB

Apart the fact that the script returned "undefined" - I must still 
investigate what's this - no crash happened, and the maximum recursion 
deep I reached is less than 20 levels (debugging with FF).

This is not to say you are wrong and I am right, but probably you are 
referring to very particular circumstances, while I am talking about a 
server-side generated page (invoked by a [modern] browser) of about 
20-120 Kb and a - in this environment - quite safe recursive function 
that in no way can harm the hosting environment.
//----------------------

As one can see, It is hardly understandable your feeling offended.
I simply had no time to further investigate, since for me right now it's 
mainly an academic question. I use that poor script in a strictly 
controlled environment and wanted just to be sure the function didn't 
cause a crash, so I tested it in a BIG document (and had no crashes).

Please note that I decided to spend time in that particular test because 
your comments, so I think this fact demonstrates I take seriously what 
you say and am simply trying to better understand things.

But even if I respect an opinion, I should not be supposed to accept it 
blindly. I have the right to use my brain to make distinctions.

Unfortunately the script failed for some reason, ok, and maybe one day 
or another I will make some further test (but my primary intent was to 
evaluate the risk of *crashes*).


>
> Score adjusted
>

Unfair.

Dan

-- 
"Everybody should pay taxes with a smile"
I tried, but they want money.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 09:59 +0200
  Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-15 11:59 +0200
    Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-15 12:03 +0200
    Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 13:36 +0200
      Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-19 12:27 +0200
        Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-19 12:34 +0200
        Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 12:08 +0200
          Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-25 14:11 +0200
            Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-25 21:22 +0200
              Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-27 16:12 +0200
    Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-08 04:50 +0200
      Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-08 09:33 +0200
        Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-12 00:48 +0200
          Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-12 01:18 +0200
            Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-13 23:26 +0200
              Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-16 08:48 +0200
                Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-20 02:11 +0200
  Re: Recursive function to find a node in the DOM Scott Sauyet <scott.sauyet@gmail.com> - 2015-07-18 15:59 -0700
    Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 12:30 +0200
      Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 13:53 +0200
        Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 14:51 +0200
          Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 16:05 +0200
            Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 20:35 +0200
            Re: Recursive function to find a node in the DOM Scott Sauyet <scott.sauyet@gmail.com> - 2015-07-30 22:10 -0700
              Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-08-06 10:07 +0200
                Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-06 20:15 +0200
                Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-08-08 01:21 +0200
        Re: Recursive function to find a node in the DOM Scott Sauyet <scott.sauyet@gmail.com> - 2015-07-30 22:09 -0700
  Re: Recursive function to find a node in the DOM Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-29 03:04 +0000
    Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-08-06 10:20 +0200

csiph-web