Giter VIP home page Giter VIP logo

Comments (9)

dotnetCarpenter avatar dotnetCarpenter commented on June 16, 2024

I haven't checked if there are any checks that should have been disabled but is not, when type checking is disabled. But I suspect that is not the case.

There is a stage 2 proposal, JavaScript Records & Tuples Proposal, that might be leverage to gain speed while ensuring constraints. I will need to look into that.

Here is an explanation of that proposal: https://2ality.com/2020/05/records-tuples-first-look.html

from sanctuary-pair.

Avaq avatar Avaq commented on June 16, 2024

I think this problem generalizes to all Sanctuary ADTs with conditional type class instances. That's most of them, I guess.

from sanctuary-pair.

dotnetCarpenter avatar dotnetCarpenter commented on June 16, 2024

Would it be possible to detect if check types is false and then have a fast path in that circumstance?

from sanctuary-pair.

Avaq avatar Avaq commented on June 16, 2024

I'm guessing no, because it would alter the behaviour of the code if checkTypes is false. It's doing the deep value inspection because it needs to figure out if it can attach a method to the container. And other parts of the code check for the existence of this method to determine how to dispatch certain operations.

from sanctuary-pair.

dotnetCarpenter avatar dotnetCarpenter commented on June 16, 2024

Looks like we can loose the same type test in Z.lte since it is already done for Setoid / Z.equals and an Ord must be a Setoid, right?
If yes, then there might be more tests that can be dropped due to the type classes hierarchy.

from sanctuary-pair.

dotnetCarpenter avatar dotnetCarpenter commented on June 16, 2024

I tried to change the constructor to see if I could speed up the validation by being less thorough. There was literally no difference!

Original: parse: 6.758s
Fast path: parse: 6.462s

  const fastPath = fst => snd => {
    const pair = Object.create (prototype);

    if (typeof fst === typeof snd) {
      pair['fantasy-land/equals'] = Pair$prototype$equals;

      if ( !(fst instanceof Function) && !(snd instanceof Function) ) {
        pair['fantasy-land/lte'] = Pair$prototype$lte;
      }
    }

    if (fst.concat instanceof Function || typeof fst === 'object') {
      if (snd.concat instanceof Function || typeof snd === 'object') {
        pair['fantasy-land/concat'] = Pair$prototype$concat;
      }

      pair['fantasy-land/ap'] = Pair$prototype$ap;
      pair['fantasy-land/chain'] = Pair$prototype$chain;
    }

    pair.fst = fst;
    pair.snd = snd;

    return pair;
  }

from sanctuary-pair.

dotnetCarpenter avatar dotnetCarpenter commented on June 16, 2024

After taking another look at the profile image, I now suspect that it is concat that is being slow. Another very strange behavior I just noticed is that if I use unchecked then I get 1-2 second speedup!

S.unchecked.reduce (parse) (S.Pair ({}) ([])),

I suspect that process.env.NODE_ENV = 'production' is not working as intended.

from sanctuary-pair.

dotnetCarpenter avatar dotnetCarpenter commented on June 16, 2024

Apparently process.env.NODE_ENV = 'production' and S.unchecked is not the same in nodejs while both have the same run time performance in the browser.

In a browser: https://dotnetcarpenter.github.io/common-scandi-names/performance.html
Source: https://github.com/dotnetCarpenter/common-scandi-names/blob/a6d92bfa3787653a14ba4385a4efe2d0c6c5f9c6/vite/pair-performance-issue.js

In nodejs 18.0:

$ node dev/pair-performance-issue.js
The test run will start in 2 seconds...
parse_: 1.590s
parse2: 4.185ms
parse: 6.243s

Source: https://github.com/dotnetCarpenter/common-scandi-names/blob/a6d92bfa3787653a14ba4385a4efe2d0c6c5f9c6/dev/pair-performance-issue.js

from sanctuary-pair.

dotnetCarpenter avatar dotnetCarpenter commented on June 16, 2024

I'm might revisit this later to see if there is any checking that can be omitted, since it does not appear to be the checks in the Pair constructor. But I'm inclined to give up and close this. Now I know that in any hot loop, I will need to use js native containers.

from sanctuary-pair.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.