• thingsiplay@lemmy.ml
    link
    fedilink
    arrow-up
    8
    ·
    4 days ago

    Please include the language or at least the software in question in post title. So this is about JavaScript, right?

  • TehPers@beehaw.org
    link
    fedilink
    English
    arrow-up
    11
    ·
    4 days ago

    TL;DR:

    So instead of creating every row.getValue(), row.getUniqueValues(), etc. method for each row object potentially millions of times, we create them just once and then assign them to the row prototype, and then just assign the prototype to the new row object.

    They go into how their needs are too dynamic for classes as well.

    Anyway, from a memory usage perspective, this makes a lot of sense. Modern JS makes liberal use of objects, but there is very little concern towards the consequences of that. Shared logic that can be decoupled from objects should be, at least from a performance standpoint.

    • ISO@lemmy.zip
      link
      fedilink
      arrow-up
      2
      ·
      3 days ago

      Manual runtime type classes!

      And I thought “stringly typed” couldn’t be topped in webshit meme-ry.

      Man, webshits are funny 😊

    • ignirtoq@feddit.online
      link
      fedilink
      English
      arrow-up
      4
      ·
      4 days ago

      I learned about JavaScript’s prototype-based inheritance model a decade ago. It’s different from every other major language, but it’s interesting and useful when used the right way. I’m astonished (1) people are still rediscovering “optimization” techniques like are described in the article when that’s how their constructors should have been designed from day-one, and (2) the JavaScript language still hasn’t added more language features to make the mutated-prototype inheritance pattern less verbose and more ergonomic. It’s a core architecture of the language and hasn’t been improved, it looks like, since the first time I read about it 10 years ago. They added the whole class syntax sugar to hide the differences in the language’s inheritance model, so they can add some improvements to the syntax for the better optimized inheritance pattern.