Performance and Comparison

Why WASM for Hydra SDK?

Hydra SDK leverages WebAssembly (WASM) to overcome the limitations of traditional JavaScript-based SDKs like @cardano-sdk. Here’s why WASM is the optimal choice:

Key Advantages of WASM

  1. Eliminates Node.js Core Module Dependencies:
    • WASM allows critical functionalities (e.g., cryptography, CBOR parsing, transaction building) to run in a sandboxed environment without relying on Node.js core modules like crypto, stream, or fs.
    • This ensures compatibility across both browser and Node.js environments.
  2. Reduces Bundle Size:
    • WASM loads only the required functions, avoiding the need for polyfills like crypto-browserify or stream-browserify.
    • This results in significantly smaller bundles compared to SDKs that rely on Node.js modules.
  3. Boosts Performance:
    • WASM executes cryptographic operations and transaction parsing at near-native speeds, reducing the overhead of JavaScript runtime.
  4. Cross-Platform Compatibility:
    • A single WASM binary can run seamlessly on browsers, Node.js (via WASI), and mobile platforms (via bridges).
    • This eliminates the need for complex interop between CommonJS and ESM modules.

Comparison of Cardano SDK Solutions

Detailed Comparison Table

CriteriaSDKs based on @cardano-sdkHydra SDK (WASM-based)
Browser CompatibilityRequires polyfills for Node.js core modules; some APIs (e.g., fs, net) are unavailable.Native browser support; no polyfills needed.
Bundle SizeVery large (hundreds of KB to >1MB) due to polyfills.Compact (only loads WASM + minimal JS glue code).
Node.js DependencyHigh, with direct imports of Node.js core modules.None; all core logic resides in WASM.
Interop (ESM/CJS)Prone to errors (exports is not defined, .default is not a function).No issues; pure ESM JavaScript.
Crypto/CBOR PerformanceModerate (pure JS, dependent on low-performance polyfills).High (WASM near-native speed).
Cross-Platform SupportGood for Node.js, limited for browsers.Excellent; works on browsers, Node.js, and mobile.
Tree-ShakingLimited, as Node.js imports are scattered, leading to unused code in bundles.Excellent; only required WASM functions are bundled.
Maintenance & ScalabilityComplex, as it requires tracking Node.js API changes and polyfills.Easy to maintain; core logic is implemented in Rust/C++ and exposed via WASM.

Dependency Flow Diagrams

Issues with SDKs based on @cardano-sdk

mermaid
graph TD
    A[App Browser] --> B[SDKs based on @cardano-sdk]
    B --> C[Node Core Modules]
    C -->|Requires Polyfill| D[crypto-browserify, stream-browserify, buffer, util...]
    D -->|Increases Bundle Size| E[Runtime Errors without Polyfill]
    C -->|Cannot Polyfill| F[fs, net -> Unusable Features]

Hydra SDK (WASM-based)

mermaid
graph TD
    A[App Browser] --> B[Hydra SDK]
    B --> C["WASM Core (Rust/C++)"]
    C --> D[WebAssembly Runtime]
    D -->|Native Browser API| E[Crypto, CBOR, Tx Builder]
    D -->|Node.js WASI| F[Crypto, CBOR, Tx Builder]

Conclusion

Hydra SDK’s WASM-based architecture provides a robust, efficient, and cross-platform solution for modern Cardano DApps. By eliminating Node.js dependencies, reducing bundle size, and boosting performance, it addresses the limitations of SDKs based on @cardano-sdk.