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

Request: Compile ord as a WASM Binary for Enhanced Integration and Performance #4099

Open
LyricalString opened this issue Nov 25, 2024 · 4 comments

Comments

@LyricalString
Copy link

Hello ord team,

I appreciate the work you’ve done on ord and its capabilities in decoding transactions and handling Bitcoin data efficiently. As ord is written in Rust, I’d like to propose an enhancement: providing precompiled WASM binaries as part of the releases.

Compiling ord to WebAssembly (e.g., using tools like wasm-pack) would significantly improve its usability and performance when integrated into other applications. Instead of spawning ord as a separate process, applications could directly invoke its functionality through a WASM runtime. This approach could drastically reduce the overhead of inter-process communication and streamline error handling, ultimately enhancing the speed of applications built around ord.

I believe this change could greatly benefit developers who rely on ord as part of larger systems, such as mine. For reference, similar optimizations have been achieved by integrating Rust-based libraries as WASM, as described in this blog: Add Some Rust to Your Old Node.js Server and My Service Performance Soared by Nearly 80%.

Would the team be open to exploring this idea? I’d be happy to assist with testing or provide more context on how this could benefit users.

Thank you for considering this suggestion!

@bingryan
Copy link
Contributor

The Ord needs to access system resources such as disk, memory, and network. The Wasm environment has limited access to these resources. BTW, ord relies on BTC node and redb. I don't think this is a good choice.

If all you have is a hammer, everything looks like a nail

@LyricalString
Copy link
Author

Got it, should I close the issue then?

@emilcondrea
Copy link
Contributor

It is actually a very good idea, played around with it but you don't want the entire Ord to be wasm binary but rather Ordinals and Runestone lib. The major blocker is the bitcoin lib which depends on native libraries and does not play well at all with wasm.

Runestone lib can be compiled to wasm quite easy when you remove bitcoin::Transaction from the interface(eg. decipher).
Easier than WASM is FFI, of course with the performance tradeoff.

@LyricalString
Copy link
Author

My use case for this started with the ord decode command. I wanted to decode transactions within my GoLang code, but the easiest solution I found was to use the binary. However, this approach requires spawning a child process, which consumes more resources compared to having the functionality as a WASM module.

I also considered using the ord server and sending requests to it, but that introduces network I/O overhead, which I’d prefer to avoid.

To clarify, I wasn’t suggesting converting the entire ord binary to WASM. My focus was more on static methods that don’t rely on internet connections, such as decoding, parsing, and similar operations.

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

3 participants