What tools/processes did you use to optimize performance here?
The main methodology was benchmarking every little line of code. Since JS has many alternatives for every thing, I had to benchmark a lot of code.
No special tools were used. The performance gains are mostly from not using recursion, less function calls etc. It could further be optimized of course (and I am working on that).
Thanks for taking the interest :)
npm install
And then: node benchmark.js
That will start the asynchronous and synchronous benchmark sequentially.Thanks for taking the interest.
Edit: benny uses the Benchmark.js library underneath.
That is not an intrinsic trait of your software, just an aspirational thing.
We are engineers not snake oil salesmen.
The claims are true intrinsic or not and they are also claims other software developers classify different libraries with.
This claim translates into: for the universe of libraries that do this same thing, this has the best performance for each one of the features this library provides.
That is claim that is not very hard to disprove. You only need 1 library that does better in one specific way and the claim is invalidated. It is a very broad claim.
Then, performance in node is very subjective. The same code can perform better or worse depending on node/v8 versions. Can perform better or worse depending on which parameters you used, or how many times a function was invoked.
You say "1m files in < 1s" but your benchmark has N=7386.
Then: what filesystem was used? was it encrypted? was it in a RAID array? There is some missing context here as well.
As for the "1m files in < 1s", yes I benchmarked that privately. That is not a false statement and to back that up, I will be uploading a gif showing the time (once the cli for fdir is done).
> The same code can perform better or worse depending on node/v8 versions.
I provided benchmarks for 2 node versions. The benchmark was fair for all libraries. It was run in the same way on the same machine for the same number of times on the same directory. So relatively the results should be fair. They were all also used barebones without parameters. Of course each library has its own approach. I cannot be held accountable for that.
> what filesystem was used? was it encrypted? was it in a RAID array? There is some missing context here as well.
You seem to have missed the whole point. You seem knowledgeable enough so let me say it in simple words. All node libraries that crawl directories for files use the `fs` module internally. Now, fs uses LibUV underneath. That is true for all libraries. There's no exception (to my knowledge). Now since the underlying i/o and the v8 engine are exactly the same, the only thing that makes the difference (and very slight at that) is the logic. Fdir wins only against other node libraries through that logic not because of some new i/o approach.
The figure 1m files in < 1s is just to give an idea of speed not to show that you'll be getting the same exact number.
I am aware of how fragile this claim is but until there comes a faster libraries I have the right to hold it. :)
- If I decide to use your code for something serious I cannot take your numbers for granted. The benchmark methodology does matter. You need show some signs of rigor so other people can assess how credible your claims are.
- Did you run this benchmark in a controlled environment without other processes running? Did you disable frequency scaling before running your benchmark? If you ran it in a desktop computer with a bunch of other stuff running and frequency scaling enabled then your processor speed was constantly oscillating while running your benchmark and the numbers are completely random.
- Did you know that v8 is full of optimizations that are conditional to how your code is written? Did you know that even a comment can dramatically affect how your code is treated by v8? In some cases V8 just gives up trying to optimize your code. Did you profile your code? did you trace v8 deoptimizations? Even if you did, you should not say this:
Why are all the other libraries so slow?
Because they did not spend enough time optimizing it.
Most developers give readability and cool code more importance
than actual performance and usability.
It's really the self-promoting tone and unbelievable claims that make the README file so irritating.
I recently created fdir mostly out of curiosity about how fast a program written in Node.js could be. It so happened that I (accidentally) created the fastest directory crawler in the NodeJS environment. fdir can easily crawl around 1 million files in under 1 second. 1 million files distributed in about 100k directories. (your mileage may vary depending on hardware).
It's also < 1kb in size (gzipped). Supports all node versions (> 6).
Feel free to give it a run and ask me any questions (if any) :D
Blog post: https://dev.to/thecodrr/how-i-wrote-the-fastest-directory-cr...
Take care, thecodrr