Re: Nested sequneces (was Contest #3 Solutions)
- Posted by euphoria at ahava.f9.co.uk Mar 14, 2002
- 413 views
> But Eu has nested sequences, making some things sooooooo much easier. > But why are nested sequences so slow, and what can we do to speed them > up? Don't nest them? Rather defeats the purpose, doesn't it? If we do not > know at runtime how much data we have per cell, we append() it as we get it. > But that makes it slower. Using getxml() in strtok.e is ****** fast(compared > with the C64 and pascal), but the code i wrote for gathering nested > premunged data for these contests is ****** slow. I remember this problem being discussed on the list several years ago. The slowness of nested sequences is to do with the way that the interpreter does them in C. blob = {a,{b,{c,{d}}}} is stored as blob = { a, pointerToX } X = { b, pointerToY } Y = { c, pointerToZ } Z = { d } using C arrays/pointers. so if I do i = blob[2][2][2][1] I end up with i = d After a long hike around RAM by the interpreter to get it for me (4 lookups) > Rob, if we had a "using" keywd, and set it to point to a subsequence, or a > nesting level, would it be possible to cache the pointers to that data, and > not > need more memory to do it? I was thinking this might bring accessing > nested levels up to the speed of the root level access? Well you will notice that David Cuny put this functionality in his preprocessor although tragically it only made the code tidier and din't put in an easy speed up. You should bear in mind that you can effectively create pointers in Euphoria. if i do junk = { 1 , 2 , 8 , 9 , { 99 , 100 , { 987, 123} } , 2948 , ...... } rubbish = junk[5][3][2] rubbish does not make a copy but simply points at the _actual_ C array. It is only copied if you change the value of rubbish. This is in the docs. The same applies with function calls if I understand correctly. You can consider arguments to be passed by reference provided you don't modify them, hence there is no large overhead in passing a monster sequence to a subroutine. I hope this helps. -- Blessings, ,úåëøá Daniel euphoria at ahava.f9.co.uk ìàéøà ìàéðã - The fear of the Lord is the beginning úòã úéùàø éé úàøé of knowledge But fools despise wisdom and discipline åæá íéìéåà øñåîå äîëç Proverbs 1:7 æ:à éìùî