wabt icon indicating copy to clipboard operation
wabt copied to clipboard

Fix interpreter to run opcodes consecutively

Open clover2123 opened this issue 2 years ago • 4 comments

For better performance, I fixed the interpreter to run opcodes consecutively rather than single execution for each opcode.

clover2123 avatar Jul 18 '22 08:07 clover2123

From a simple evaluation below, this patch showed a significant performance improvement.

// fibonacci calculation
#include <stdio.h>

int fib(int n) {
  if (n == 1) return 1;
  if (n == 2) return 1;
  return fib(n-1) + fib(n-2);
}

int main()
{
    fib(30);
    return 0;
}

Performance Result

  • This patch : 22.1 sec
  • Origin : 25.1 sec

clover2123 avatar Jul 18 '22 08:07 clover2123

@sbc100 I'm using wasm-c-api to run wasm codes in my project. And AFAIK wabt is the only wasm engine built by c/c++ that fully supports the wasm-c-api standard.

I'm also happy to contribute to this project and I'll upgrade the interpreter as much as possible not harming the overall sustainability or readability. Thanks :)

clover2123 avatar Jul 20 '22 05:07 clover2123

@sbc100 I'm using wasm-c-api to run wasm codes in my project. And AFAIK wabt is the only wasm engine built by c/c++ that fully supports the wasm-c-api standard.

I'm also happy to contribute to this project and I'll upgrade the interpreter as much as possible not harming the overall sustainability or readability. Thanks :)

I though that v8 supported that API? Does it not? What about wasmtime?

In any case, its great that you are using wabt and we will happily accept your patches, but please bear in mind that the wabt is probably not the best choice for a production runtime.. at least not in the long term.

sbc100 avatar Jul 20 '22 06:07 sbc100

@sbc100 I need a lightweight wasm engine for several reasons now, so I choose wabt.

wasmtime is also one of good alternatives, but unfortunately it is based on rust language 😢 I'll keep in mind your advice Thanks :)

clover2123 avatar Jul 20 '22 06:07 clover2123

it might be possible to simply add an appropriate inline attribute instead?

SoniEx2 avatar Mar 05 '23 20:03 SoniEx2

Hi -- is there still interest in merging this (in which case I think the diff should probably be cleaned up to avoid re-formatting those big sections), or should we close as dormant?

keithw avatar Jun 12 '23 22:06 keithw

This has been inactive for a long time, so I close it.

clover2123 avatar Jul 01 '23 04:07 clover2123