-
Notifications
You must be signed in to change notification settings - Fork 36
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
Reason for using node-gyp? #103
Comments
Because the native version is a lot faster. |
FWIW, prebuilt binaries are included in the npm package for the most common platforms (Linux x64, Windows ia32 & x64, macOS x64 + arm64) so node-gyp is not used in most cases. |
@lpinca oh ok, that wasn't obvious from looking through the README/ sources, I think this deserves a mention in the README |
I think it is obvious if you look at the module entry point and |
Ok ehm so, I was intrigued by this and did some perf tests here: https://replit.com/@webketje/utf8check-perf Below is the result of a single run (but the results wildly varied for the text file tests) Benchmark results
Interesting to note and what was consistent across multiple runs, is that when run on a relatively large binary file (eg .jpg, .zip), native utf-8-validate (precompiled) was up to 10x slower than "fallback", and both were outperformed by is-utf8 |
In this case the first few bytes are probably not valid UTF-8, so the cost of calling C++ from JS does not pay off. This is confirmed by the fact that there is no difference between the 5MB and 12MB file. See #90, websockets/ws#1348, https://github.com/websockets/ws/blob/8.5.0/lib/validation.js#L114, and #101. |
I'm closing this as answered. Discussion can continue if needed. |
Hi there,
Is there any reason why the module defaults to
validation.c
(compiled with node-gyp postinstall)AFAICS the "fallback" contains the same "main" code and no important native API's are used.
Is it purely for efficiency with large files?
Context: looking for replacement for https://github.com/wayfind/is-utf8 for Metalsmith SSG, due to erroneous handling of ASCII chars, see wayfind/is-utf8#6 but cannot consider any lib that requires node-gyp (due to platform-specific issues)
So this request would be to justify node-gyp dependency overhead in the docs and/ or make it an optionalDependency (as
require('utf8-validate/fallback')
should also workThe text was updated successfully, but these errors were encountered: