Add simple profiling / Basic benchmark & README update #128
Conversation
10fef5c
to
8bf67a2
Compare
Hey @holgerd77, I run the profiler and confirmed that the native version of keccak is being used. I guess your confusion comes form having a frame like this The My understanding is that for the js version to be used one of these things needs to happen:
I believe all of them are highly unlikely. If one of them happens, there's not much we can do, as it means that there's no native version available. Note that there aren't other things that could fail that will lead to the js version being used, as there's no installation process that could go wrong. The prebuilt binaries come bundled within the npm package, and are just used at runtime whenever they match the os & hardware requirements. |
…enchmarking results), added simple profiling option, added README section on benchmarking
8bf67a2
to
957a515
Compare
This is now ready for re-review. |
@alcuadrado my flamegraph structure looks fundamentally different I also can't find any napi like references, so I am pretty sure that I am using plain JS. I also renamed the Then I did a fresh installation on MPT (complete new repo and then My setup here is: MacBookAir 2013 (Intel Core i5), Mojave, Node v12.15.0. So it might be worth to further investigate here if this is something systemic and breaks the assumptions made on the It would be good if others could tell from their setups and their perceived keccak installation. My first-round take away from this is still what we discussed on the call: that it is very much too intransparent what version is used on runtime. The code on the On a very low level it would already help to rewrite these code parts in a more readable way and/or add some simple comments. |
Hey @holgerd77, thanks for investigating this further.
I may be missing something, but I don't see how that portion of the flamegraph is relevant. There's no mention of I'm still not sure if you are using the native version. (PS: I added a way to validate this lower in this comment)
What do you mean by
Thanks for trying this. I've fallen into that trap so many times 😅
I wonder if Mojave has anything to do here. Let'a first validate that you are actually using the js version, and if that's the case I'll use a vm to reproduce it.
I think this is what is confusing me/us the most. I created that list and I believe it's correct. Sorry for not being clear on that. These assumptions are not made by const napiLoader = require("lib-that-know-how-to-load-napi-things");
try {
module.exports = napiLoader("./prebuilds");
} catch (e) {
module.exports = require("./pure-js.js");
} so there's no actual place where those assumptions are checked. This works exactly the same as feature detection works on the web.
I completely agree with this. As I wrote on discord, we should decide if we want to ask the maintainers of keccak and other native bindings to expose this information at runtime, and also come up with a way of doing that, as printing a message at runtime is not a valid option. If this info is available, I'll export it in
To be really honest, I don't think this is the case. The entry point of the library is, as usual, try {
module.exports = require('./bindings')
} catch (err) {
module.exports = require('./js')
} You can manually check which version is being used by adding Also, I do find Anyway, thanks for digging deeper into this. Can you check if you are actually using the native version by adding those |
Meant
That was one of the first things I tried some time before I have been writing the post from above. I was so convinced that this went the 1 ->2 way (see modified quote from above). Now I tried again and it went 1 -> 3. 🤨 So seems the native version gets executed. Sorry for all the inconvenience. (I am still a bit unsettled since I was not able yet to find any What Node version are you actually using? Maybe I'll try run profiling with that version and see if anything changes. |
add comment about how to look at the profiler results
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.
LGTM!
@holgerd77 If 3 was printed then you are using the js version. Can you also print
I may have generated some confusion. The napi frames are tiny and took me a while to find them. But if
I'm using node v10.22.0 on a fully updated macos installation. |
I still had a folder renamed which let things break, now I fixed and it is going 1 ->2 again, sorry for all the chaos. |
No problem, I'm relieved that it's working as expected :) |
Hi @alcuadrado, I thought it would be the most sustainable option to create a PR on your request to send the MPT flamegraph, especially since sending around an HTML flamegraph is a bit tricky.
The PR integrates basic profiling on the library, I also updated the
random.ts
benchmark a bit, this was actually already quite similar before in comparison to my code I had for profiling.This PR is of course just one small step to first-introduce this basic profiling here. Everyone feel free to change on everything on subsequent PRs. Once this is merged it should be easily doable to generate a flamegraph with: