Skip to content
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

modpow in 0.3 (128 bit support) degrades performance for WASM #156

Open
ra-- opened this issue Jun 22, 2020 · 1 comment
Open

modpow in 0.3 (128 bit support) degrades performance for WASM #156

ra-- opened this issue Jun 22, 2020 · 1 comment

Comments

@ra--
Copy link

ra-- commented Jun 22, 2020

num-bigint 0.3 introduced 128 bit integer support, which significantly improves modular exponentation. On my machine with arbitrary 256 bit inputs, modpow() improved from 94 ms to 24 ms from num-bigint version 0.2 to version 0.3 respectively. With Wasm code generated by modpow() from num-bigint's version 0.2, I observe an execution time of 125 ms, which seems a reasonable overhead. I expected to observe some performance improvement from num-bigint 0.3 to translate over to Wasm as well, but the opposite seems to be the case. Instead of improving, execution time degrades from 125 ms to 148 ms. Is this a known issue?

Summary:
modpow() num-bigint v0.2: 94 ms -> Wasm 125 ms
modpow() num-bigint v0.3: 24 ms -> Wasm expected ~32 ms, but at least < 125 ms. observed 148 ms.

@ra-- ra-- changed the title modpow improvement from 0.3 (128 bit support) does not translate over to WASM modpow improvement from 0.3 (128 bit support) degrades performance for WASM Jun 22, 2020
@ra-- ra-- changed the title modpow improvement from 0.3 (128 bit support) degrades performance for WASM modpow in 0.3 (128 bit support) degrades performance for WASM Jun 22, 2020
@cuviper
Copy link
Member

cuviper commented Jun 26, 2020

The new 64-bit digits are only used for target_pointer_width = 64. Since the only Wasm targets are wasm32-* so far, they won't get the new digit size by default. So at first glance, I would not expect wasm32 running on x86_64 to get any part of the same speedup as native x86_64.

The montgomery modpow also got a big rewrite in bb3e3b1, regardless of digit size.

Here are my own native results, and for fun I also tried forcing alternate digit sizes.

i686-unknown-linux (ns/iter)

bench 0.2.6 0.3.0 0.3.0 (u64)
modpow 23,260,377 18,386,342 15,552,574
modpow_even 81,104,677 80,563,416 94,701,085

x86_64-unknown-linux (ns/iter)

bench 0.2.6 0.3.0 0.3.0 (u32)
modpow 18,742,629 3,914,476 13,402,402
modpow_even 39,494,004 34,533,942 43,222,990

Those are using 2048-bit inputs, so your 256-bit inputs could well hit different hotspots. And I'm not sure how to predict what Wasm JITs will do with all of this. If you have a way to actually profile that, it could be helpful.

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

No branches or pull requests

2 participants