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


Groups > comp.lang.javascript > #30654

Re: Impact of implicit arrays...

From "Chris M. Thomasson" <nospam@nospam.com>
Newsgroups comp.lang.javascript
Subject Re: Impact of implicit arrays...
Date 2016-06-13 12:23 -0700
Organization Aioe.org NNTP Server
Message-ID <njn17d$8h2$1@gioia.aioe.org> (permalink)
References <njhj52$hl3$1@gioia.aioe.org> <86226397.ynjsKikP0V@PointedEars.de>

Show all headers | View raw


> Chris M. Thomasson wrote:
> […]
> function ct_complex_add(c0, c1)
> {
>     return [c0[0] + c1[0], c0[1] + c1[1]];
> }
> […]
> function ct_complex_sub(c0, c1) {
>     return [c0[0] - c1[0], c0[1] - c1[1]];
> }
> […]
> ______________________________
>
>
> If I call any of the functions above in a large
> iteration, will memory start to explode and stress
> out the garbage collector? I mean will there be
> millions of arrays that are allocated during heavy
> load?


> > "Thomas 'PointedEars' Lahn" wrote:

> > The only good answer to such questions is “try and see”.  You can start 
> > with
> > a small example and see how the approach scales in various runtime
> > environments.  You might see a pattern emerging if the same ECMAScript
> > implementation is used.

Excellent advise. So far it seems to be okay, but I have
the feeling that it can still blow up.


> This is purely functional implementation. Can
> an intrusive technique give better performance?

> > Mu.

> > I referred to my JSX:math/complex.js before, so you are reinventing the
> > wheel (but you might do it better), but the only real difference to your
> > approach is that mine is *more* object-oriented: there are Complex 
> > instances
> > (arrays *are* objects too, so your approach is _not_ “purely 
> >  functional”)
> > because new Complex instances are created as the result of operations.


:^D Yeah, I am a C programmer at heart, so this type of
(ct_complex_xxx) function naming scheme is natural to me.
Also, so is returning arrays that do not need to be allocated.
That's the main source of my worry.


> > Creating new objects when operating on complex values (literally and
> > figuratively) can only be avoided if an operation function modifies the
> > object and returns a reference to the modified object.  Or one can, with
> > loss of precision and performance, operate only on string 
> > representations,
> > hoping that the script engine does not create objects from them unless
> > necessary, i.e. unless String methods are called.  Is one of those what 
> > you
> > mean by “an intrusive technique”?

YES! Intrusive means to change the inputs from (input only)
to (input/output) parameters. So, take the snippet of my
code you saved wrt (ct_complex_add). The intrusive analog
of this could be:

// IMVHO, functional...
> function ct_complex_add(c0, c1)
> {
>     return [c0[0] + c1[0], c0[1] + c1[1]];
> }


IMHO, this following code is not so functional!
Its intrusive... ;^o
______________________________
function ct_complex_add(c0, c1)
{
     c0[0] += c1[0];
     c0[1] += c1[1];
     return c0;
}
______________________________


I can do this, but it requires the caller needs to respect the
fact that actual function parameters will be changed. However,
there will be no chance of a new array being created on each
call to this function wrt intrusive design.

;^) 

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


Thread

Impact of implicit arrays... "Chris M. Thomasson" <nospam@nospam.com> - 2016-06-11 10:52 -0700
  Re: Impact of implicit arrays... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-12 12:16 +0200
    Re: Impact of implicit arrays... "Chris M. Thomasson" <nospam@nospam.com> - 2016-06-13 12:23 -0700
  Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-13 22:00 -0700
    Re: Impact of implicit arrays... "Chris M. Thomasson" <nospam@nospam.com> - 2016-06-14 17:17 -0700
      Re: Impact of implicit arrays... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-15 06:55 +0200
      Re: Impact of implicit arrays... "Chris M. Thomasson" <nospam@nospam.invalid> - 2016-06-14 22:19 -0700
      Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-18 12:47 -0700
        Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-21 14:43 -0700
          Re: Impact of implicit arrays... "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-22 00:10 +0200
            Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-21 15:28 -0700
              Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-21 15:31 -0700
                Re: Impact of implicit arrays... "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-22 11:55 +0200
                Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 12:23 -0700
                Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 14:14 -0700
                Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 14:16 -0700
                Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 18:14 -0700
                Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 18:46 -0700
          Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-21 17:35 -0700
            Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-21 21:08 -0700
              Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-21 23:09 -0700
                Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 14:38 -0700
                Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-24 07:16 -0700
                Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-25 18:03 -0700
                Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-25 18:24 -0700
                Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-01 13:52 -0700

csiph-web