-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
improve performance #2
Conversation
Hi there, thanks for the PR. Can you add all this to a new “src/unsafe.js” file? Because this uses |
Codecov Report
@@ Coverage Diff @@
## master #2 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 2 +1
Lines 10 16 +6
=========================================
+ Hits 10 16 +6
Continue to review full report at Codecov.
|
@lukeed Some performance gain could be also achieved for the "safe"-version like this: var i=0,HEX=[];
while (i<256) HEX[i]=(256+i++).toString(16).substring(1);
export default function (len) {
len||(len=16);
var str='',lh =((1+len)>>1)-1,num=lh;
while (num--) str += HEX[255*Math.random()|0];
return function () {
if (num === 255) {
str=''; num=lh;
while (num--) str += HEX[255*Math.random()|0];
}
return str + HEX[++num];
};
} |
If you just add a new file I’ll take care of the rest :) |
patch performance of index.js
done |
I think something is off with the index tracking? I'm running the collisions script ( |
Math.random returns a number between 0 (inclusive) and 1 (exclusive). So it would only be number between 0 and 254 and not 255, increasing the collisions. Fixed it. |
The benchmarks dont work. I need to change it to |
Ok.. odd length fails now. Any wish how to solve it? I assume, that was the original reason for doing the substring? |
Or was it already broken before? |
Right, that looks more correct, but I also realized that odd-numbered lengths are not respected. That's part of what the substring was for previously. Updated the benchmark usage too, btw. |
Odd lengths worked previously. Updating the base branch w/ cherry picked commits |
I think i could unify both, normal and unsafe, and enable unsafe by setting a second parameter to true. Should increase the maintanability of the code... |
I prefer the multiple files – doesn't affect maintainability at all. Plus any presence of |
An ok. Didnt know that. |
@lukeed can you have look at it,plz? |
Can we call it something different than unsafe? It does not really sound appealing to use "unsafe". I am currently thinking how we could name it. |
Can we call it |
@lukeed |
Sorry traveling |
Yeah enjoy your travelling ;). I am currently in Paris travelling. I was just wondering if there is a technical reason for stalling this PR ;). So again: Enjoy your travelling. :) |
I renamed unsafe to jit |
Are you taking a sabbatical :)? |
Closing due to inactivity. I also adapted my changes directly into fastify-multipart. |
Hi @lukeed ,
with this PR we generate a id-function on the fly. There are also various changes like avoiding substring calls and initializing the HEX-Lookup-Table with index 0.
before:
after:
Benchmarks made on node v14.19.1
@mcollina
@kibertoad