![]() ![]() Writing one set of tests proved to be quite challenging (I had erroneously assumed that puppeteer would make browser testing trivial) but success was achieved. I’m all for simplicity, but I need tests that execute in the browser. I’ve noticed that some packages just mock the browser environment in node, but this doesn’t give me confidence. One of the goals I had in developing highwayhasher is to reuse the same test code for both node and browser environments as any feature or bugfix found in one must be equally represented in the other. The one nice thing is that we can implement the new API entirely in JS when implementing it in rust brings no benefits. You can then retrieve a certain value by using the key for that value, which you put into the table beforehand. Interestingly, the Wasm side isn’t as nearly as affected, but we must still add these new API methods to the Wasm side to adhere to the isomorphic API requirement. Hash Tables are a data structure that allow you to create a list of paired values. So when performance is key, one should design their API to allow users to call methods that reduce the number of N-API calls. Even at larger input sizes (~1 MB) there can be a throughput improvement of 10-15%.Hashing data with a length of 1 doubled in throughput (0.17 MB/s to 0.38 MB/s).If we replace it with a single N-API call that initializes, hashes, and finalizes in a single step there can be major performance benefits: To give an example, the snippet has 3 N-API calls: HighwayHash is a fast enough hash function that the performance penalty of leaving the land of JS is tangible. I mark all node imports (in highwayhasher’s case, it’s just os) as external in the rollup config to let rollup know to not resolve it (and I wasn’t about to add a dev dependency for just this functionality). This is why we define multiple entry points for our package. One may be alarmed that we’re importing functions from the node specific os module in a package designed for browser use, but we’re safe as long as the above snippet is never referenced from the root of index_browser. Interestingly the underlying bug in the issue I linked above was due to a misuse of N-API, and while I would never voice this out loud and be accused of unnecessary rust evangelism, I’m curious if rust N-API bindings could have prevented this class of bugs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |