Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Add benchmarks for db-level dispatch calls. #57

Merged
merged 1 commit into from
Jul 21, 2020

Conversation

whiten
Copy link
Contributor

@whiten whiten commented Jul 21, 2020

These are novel in that the benchmark loop executes in JS space and each
iteration calls into Rust and transfers the response back to JS.

Example run:

% ./tool/benchmark dispatch
Hardware: 8-Core Intel Core i9 2.4 GHz, 32 GB RAM, 1 TB SSD

dispatch::has           483   2,141,490 ns/iter
dispatch::get1024       468   2,229,690 ns/iter   0.46 MB/s
dispatch::get4096       459   2,273,355 ns/iter   1.80 MB/s
dispatch::get16384      438   2,463,367 ns/iter   6.65 MB/s
dispatch::put1024       100  23,429,150 ns/iter   0.04 MB/s
dispatch::put4096       100  35,972,949 ns/iter   0.11 MB/s
dispatch::put16384      100  57,210,150 ns/iter   0.29 MB/s
dispatch::random4096  10855     108,412 ns/iter  37.78 MB/s

These are novel in that the benchmark loop executes in JS space and each
iteration calls into Rust and transfers the response back to JS.

Example run:

% ./tool/benchmark dispatch
Hardware: 8-Core Intel Core i9 2.4 GHz, 32 GB RAM, 1 TB SSD

dispatch::has           483   2,141,490 ns/iter
dispatch::get1024       468   2,229,690 ns/iter   0.46 MB/s
dispatch::get4096       459   2,273,355 ns/iter   1.80 MB/s
dispatch::get16384      438   2,463,367 ns/iter   6.65 MB/s
dispatch::put1024       100  23,429,150 ns/iter   0.04 MB/s
dispatch::put4096       100  35,972,949 ns/iter   0.11 MB/s
dispatch::put16384      100  57,210,150 ns/iter   0.29 MB/s
dispatch::random4096  10855     108,412 ns/iter  37.78 MB/s
@whiten whiten merged commit 7e21f0f into rocicorp:master Jul 21, 2020
wt.commit().await.unwrap();

b.reset_timer();
eval(&format!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little concerned about the use of eval (assuming that's what's happening under the covers here) deoptimizing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interested to hear more. What do you mean by that? And yes, this is using JS's eval to construct a benchmark of how long these functions take from a JS context. I should create a parallel copy of some of these that executes solely in wasm to isolate the difference that comes from the JS->wasm hop, but I'll wait for more feedback first.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of things js can do to accidentally trigger the jit to stop optimizing. i think eval might be one of those things. I don't know a lot about it, just to be wary of it. I'm not sure if it would just de-optimize this loop, or potentially what it's calling into like the marshaling code. @arv might know more.

Copy link
Contributor

@aboodman aboodman Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically I don't know if using eval() is a good simulation of somebody using the js library, but I know enough to know it's something to look at.

I guess you could find out the answer by running this in a browser and looking in the web inspector at the profiler. I know it marks functions that have been deoptimized:

GoogleChrome/devtools-docs#53

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This eval looks fine since it is only used once at the top level of the computation.

Copy link
Contributor

@arv arv Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if there is any kind of iteration of the rust function has then this is not going to be a realistic benchmark.

(async _ => {{
var array = new Uint8Array({});
for (let i = 0; i < {}; i++) {{
window.crypto.getRandomValues(array);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be inside the benchmark. It is probably slow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And deopts

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants