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 #100
Improve performance #100
Conversation
index.js
Outdated
@@ -5,9 +5,9 @@ const oxmlContentTypes = toBytes('[Content_Types].xml'); | |||
const oxmlRels = toBytes('_rels/.rels'); | |||
|
|||
module.exports = input => { | |||
const buf = new Uint8Array(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional, for browser support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this make new buffer it It takes performance.
Why an array of numbers is not good for checking?
I appreciate the PR, but it's missing a benchmark proving the numbers you claim :) |
try this const fs = require('fs');
const filetype = require('.');
var file = fs.readFileSync(__dirname + "/fixture/fixture.png");
var time = 3000;
var starttime = Date.now();
var endtime = starttime + time;
var count = 0;
for(;Date.now()<endtime;count++){
filetype(file);
}
console.log("%d ops/s" ,~~(count/((Date.now()-starttime)/1000))); |
@mifi Any thoughts on this? |
index.js
Outdated
|
||
if (!(buf && buf.length > 1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit unclear why u compare with -1, why not use buf[1] !== undefined ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It checks that it is also a number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that needed? also '' > -1
is true
which is obviously not a number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a check that on the way.
It's not important
I dunno if some of our users are sending in an array, but if they do, some file type checks will fail when removing the wrapping, like those using Also, is it the removal of the wrapping or the length check that boosts performance? |
What's important for performance. |
Ok, I think then you can revert the |
Ok, sure, when @mifi's feedback is addressed. |
No description provided.