-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pair is at least 80% slower than using an Array 2-tuplet #50
Comments
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 |
I think this problem generalizes to all Sanctuary ADTs with conditional type class instances. That's most of them, I guess. |
Would it be possible to detect if check types is |
I'm guessing no, because it would alter the behaviour of the code if checkTypes is |
Looks like we can loose the same type test in |
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 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;
} |
After taking another look at the profile image, I now suspect that it is S.unchecked.reduce (parse) (S.Pair ({}) ([])), I suspect that |
Apparently In a browser: https://dotnetcarpenter.github.io/common-scandi-names/performance.html In nodejs 18.0:
|
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. |
I had an issue with a super simple parser that took seconds to parse simple objects. After profiling, I found the bottleneck to be
Pair
. Changing fromPair
to anArray
Tuple made my use-case go from seconds to 40ms!I made a reduced test case here: https://dotnetcarpenter.github.io/common-scandi-names/performance.html
All tests and profiles I have made are with type checking disabled.
Using
S.Pair
is at least 80% slower than using an Array 2-tuplet, in this simple parsing test usingS.reduce
. Wheretokens
are https://gist.github.com/dotnetCarpenter/a52ff00f8d9a1cf1fcff23114a0fabea#file-norwegian-tokens-js.You should be able to copy/paste the code from this gist into nodejs and see the difference (the two data sets are also in the same gist.
Even with the mangled files names due to rollup/vite bundling, it is still easy to spot where the majority of time is spent.
Pair
does rigorous testing regardless of type checking mode, in order to know which ADT's to implement. A fix would need to make sure that these tests will still function.The text was updated successfully, but these errors were encountered: