Sign in

    wite

    Component-model-aware WebAssembly analyzer, optimizer, and profiler

    wasm
    component-model
    optimizer
    profiler
    Download zip
    Author
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    8 months ago
    Downloads
    65K

    #wite

    WebAssembly analyzer/optimizer/profiler for core wasm and component model binaries.

    // See README.md and src/lib.mbt for usage.

    WiteError

    pub suberror WiteError {
    UnexpectedEof
    InvalidMagic
    UnsupportedVersion(String)
    InvalidFormat(String)
    }

    CallGraphNode

    pub struct CallGraphNode {
    function_index : UInt
    body_bytes : UInt
    name : String?
    export_names : Array[String]
    direct_callees : Array[UInt]
    reachable_from_roots : Bool
    }

    CallGraphReport

    pub struct CallGraphReport {
    imported_function_count : UInt
    local_function_count : UInt
    roots : Array[UInt]
    has_indirect_calls : Bool
    partial : Bool
    reachable_body_bytes : UInt
    dead_body_bytes : UInt
    nodes : Array[CallGraphNode]
    }

    CallGraphSummary

    pub struct CallGraphSummary {
    imported_function_count : UInt
    local_function_count : UInt
    roots : Array[UInt]
    has_indirect_calls : Bool
    partial : Bool
    reachable_function_count : UInt
    dead_function_count : UInt
    reachable_body_bytes : UInt
    dead_body_bytes : UInt
    }

    CodeBlockSize

    pub struct CodeBlockSize {
    function_index : UInt
    function_name : String?
    export_names : Array[String]
    block_index : UInt
    depth : UInt
    kind : String
    start_offset : UInt
    end_offset : UInt
    instruction_count : UInt
    total_bytes : UInt
    }

    CodeBlockSizeReport

    pub struct CodeBlockSizeReport {
    partial : Bool
    function_count : UInt
    block_count : UInt
    total_body_bytes : UInt
    total_instruction_bytes : UInt
    blocks : Array[CodeBlockSize]
    }

    ComponentCallGraphReport

    pub struct ComponentCallGraphReport {
    module_index : UInt
    graph : CallGraphReport
    }

    ComponentCoreOptimizeEntry

    pub struct ComponentCoreOptimizeEntry {
    module_index : UInt
    before_bytes : UInt
    after_bytes : UInt
    removed_sections : Array[String]
    no_change_reasons : Array[String]
    }

    ComponentCoreOptimizeReport

    pub struct ComponentCoreOptimizeReport {
    total_component_bytes : UInt
    core_module_count : UInt
    total_core_before_bytes : UInt
    total_core_after_bytes : UInt
    entries : Array[ComponentCoreOptimizeEntry]
    }

    ComponentFunctionSizeReport

    pub struct ComponentFunctionSizeReport {
    module_index : UInt
    function_count : UInt
    total_body_bytes : UInt
    functions : Array[FunctionSize]
    }

    ComponentProfile

    pub struct ComponentProfile {
    total_bytes : UInt
    import_count : UInt
    export_count : UInt
    core_module_count : UInt
    nested_component_count : UInt
    sections : Array[SectionSize]
    core_modules : Array[ModuleProfile]
    }

    ComponentRootPolicyReport

    pub struct ComponentRootPolicyReport {
    component_imports : Array[String]
    component_exports : Array[String]
    wit_imports : Array[String]
    wit_exports : Array[String]
    canonical_abi_roots : Array[String]
    root_name_candidates : Array[String]
    }

    ContractReport

    pub struct ContractReport {
    component_imports : Array[String]
    component_exports : Array[String]
    wit_imports : Array[String]
    wit_exports : Array[String]
    missing_component_imports : Array[String]
    missing_component_exports : Array[String]
    }

    CustomSectionBreakdown

    pub struct CustomSectionBreakdown {
    name : String
    count : UInt
    total_bytes : UInt
    payload_bytes : UInt
    content_bytes : UInt
    }

    DceReport

    pub struct DceReport {
    roots : Array[UInt]
    partial : Bool
    removable_function_count : UInt
    removable_body_bytes : UInt
    removable_functions : Array[FunctionSize]
    }

    FunctionGapEntry

    pub struct FunctionGapEntry {
    match_kind : String
    match_key : String
    left_function_index : UInt?
    right_function_index : UInt?
    left_name : String?
    right_name : String?
    left_export_names : Array[String]
    right_export_names : Array[String]
    left_body_bytes : UInt
    right_body_bytes : UInt
    left_minus_right_bytes : Int
    abs_gap_bytes : UInt
    }

    FunctionGapReport

    pub struct FunctionGapReport {
    left_total_body_bytes : UInt
    right_total_body_bytes : UInt
    left_minus_right_total_bytes : Int
    unmatched_left_count : UInt
    unmatched_right_count : UInt
    entries : Array[FunctionGapEntry]
    }

    FunctionSize

    pub struct FunctionSize {
    function_index : UInt
    body_bytes : UInt
    name : String?
    export_names : Array[String]
    }

    FunctionSizeDiff

    pub struct FunctionSizeDiff {
    function_index : UInt
    before_body_bytes : UInt
    after_body_bytes : UInt
    gain_bytes : UInt
    regression_bytes : UInt
    before_name : String?
    after_name : String?
    export_names : Array[String]
    }

    HostCodeHint

    pub struct HostCodeHint {
    kind : String
    function_index : UInt
    function_name : String?
    target_function_index : UInt
    target_function_name : String?
    export_names : Array[String]
    appended_i32_const_count : UInt
    dropped_param_count : UInt
    }

    HostGeneratedCodeReport

    pub struct HostGeneratedCodeReport {
    imported_function_count : UInt
    local_function_count : UInt
    param_forwarding_thunk_count : UInt
    const_forwarding_thunk_count : UInt
    signature_refinable_thunk_count : UInt
    directize_candidate_call_count : UInt
    dce_removable_function_count : UInt
    dce_removable_body_bytes : UInt
    dce_partial : Bool
    hints : Array[HostCodeHint]
    }

    HotnessSizeBucket

    pub struct HotnessSizeBucket {
    bucket : String
    count : UInt
    body_bytes : UInt
    total_ns : UInt64
    }

    HotnessSizeEntry

    pub struct HotnessSizeEntry {
    export_name : String
    function_index : UInt?
    function_name : String?
    body_bytes : UInt
    calls : UInt
    total_ns : UInt64
    average_ns : UInt64
    bucket : String
    unresolved_reason : String?
    unresolved_detail : String?
    }

    HotnessSizeMatrixReport

    pub struct HotnessSizeMatrixReport {
    iterations : UInt
    instantiate_ns : UInt64
    hot_threshold_ns : UInt64
    large_threshold_bytes : UInt
    unresolved_exports : Array[String]
    unresolved_reason_counts : Array[HotnessUnresolvedReasonCount]
    buckets : Array[HotnessSizeBucket]
    entries : Array[HotnessSizeEntry]
    }

    HotnessUnresolvedReasonCount

    pub struct HotnessUnresolvedReasonCount {
    reason : String
    count : UInt
    }

    KeepReasonEntry

    pub struct KeepReasonEntry {
    function_index : UInt
    name : String?
    export_names : Array[String]
    reasons : Array[String]
    }

    KeepReasonReport

    pub struct KeepReasonReport {
    partial : Bool
    entries : Array[KeepReasonEntry]
    }

    ModuleProfile

    pub struct ModuleProfile {
    total_bytes : UInt
    function_count : UInt
    import_count : UInt
    export_count : UInt
    code_body_count : UInt
    code_body_bytes : UInt
    sections : Array[SectionSize]
    }

    OpcodeStat

    pub struct OpcodeStat {
    key : String
    mnemonic : String
    count : UInt
    total_bytes : UInt
    }

    OptimizeConfig

    pub struct OptimizeConfig {
    strip_all_custom : Bool
    strip_name_section : Bool
    strip_producers_section : Bool
    strip_debug_sections : Bool
    strip_dwarf_sections : Bool
    strip_target_features_section : Bool
    keep_custom_sections : Array[String]
    pass_rounds : UInt
    enable_peephole : Bool
    peephole_remove_nop : Bool
    peephole_remove_const_drop : Bool
    enable_vacuum : Bool
    enable_merge_blocks : Bool
    enable_remove_unused_brs : Bool
    enable_dce : Bool
    enable_dfe : Bool
    enable_merge_similar_functions : Bool
    enable_remove_unused_module_elements : Bool
    closed_world : Bool
    closed_world_root_exports : Array[String]
    safe_mode : Bool
    }

    OptimizeConfig::aggressive

    fn OptimizeConfig::aggressive() -> OptimizeConfig

    OptimizeConfig::default

    OptimizeConfig::o0

    OptimizeConfig::o1

    OptimizeConfig::o2

    OptimizeConfig::o3

    OptimizeConfig::os

    OptimizeConfig::oz

    OptimizeMetadataReport

    pub struct OptimizeMetadataReport {
    before_size : UInt
    after_size : UInt
    total_gain_bytes : UInt
    total_regression_bytes : UInt
    stages : Array[OptimizeStageMetadata]
    }

    OptimizeResult

    pub struct OptimizeResult {
    bytes : Bytes
    before_size : UInt
    after_size : UInt
    removed_sections : Array[String]
    no_change_reasons : Array[String]
    }

    OptimizeStageMetadata

    pub struct OptimizeStageMetadata {
    stage : String
    before_size : UInt
    after_size : UInt
    gain_bytes : UInt
    regression_bytes : UInt
    function_gain_bytes : UInt
    function_regression_bytes : UInt
    function_diffs : Array[FunctionSizeDiff]
    removed_sections : Array[String]
    no_change_reasons : Array[String]
    }

    RetainPathEntry

    pub struct RetainPathEntry {
    function_index : UInt
    name : String?
    export_names : Array[String]
    body_bytes : UInt
    root_reasons : Array[String]
    path : Array[UInt]
    }

    RetainPathReport

    pub struct RetainPathReport {
    partial : Bool
    roots : Array[UInt]
    entries : Array[RetainPathEntry]
    }

    RuntimeFunctionProfile

    pub struct RuntimeFunctionProfile {
    name : String
    calls : UInt
    total_ns : UInt64
    average_ns : UInt64
    }

    RuntimeProfile

    pub struct RuntimeProfile {
    instantiate_ns : UInt64
    iterations : UInt
    functions : Array[RuntimeFunctionProfile]
    skipped_exports : Array[String]
    unresolved_exports : Array[RuntimeUnresolvedExport]
    }

    RuntimeProfileScenario

    pub struct RuntimeProfileScenario {
    export_name : String
    args : Array[Int]
    }

    RuntimeUnresolvedExport

    pub struct RuntimeUnresolvedExport {
    export_name : String
    reason : String
    detail : String
    }

    SectionSize

    pub struct SectionSize {
    key : String
    section_id : UInt
    total_bytes : UInt
    }

    WasmBreakdownReport

    pub struct WasmBreakdownReport {
    total_bytes : UInt
    sections : Array[SectionSize]
    custom_sections : Array[CustomSectionBreakdown]
    imported_function_count : UInt
    local_function_count : UInt
    top_functions : Array[FunctionSize]
    block_count : UInt
    top_blocks : Array[CodeBlockSize]
    instruction_count : UInt
    instruction_bytes : UInt
    opcode_partial : Bool
    opcodes : Array[OpcodeStat]
    callgraph_partial : Bool
    has_indirect_calls : Bool
    reachable_body_bytes : UInt
    dead_body_bytes : UInt
    }

    analyze_call_graph

    fn analyze_call_graph(bytes : Bytes) -> Result[CallGraphReport, WiteError]

    analyze_call_graph_summary

    fn analyze_call_graph_summary(bytes : Bytes) -> Result[CallGraphSummary, WiteError]

    analyze_code_block_sizes

    fn analyze_code_block_sizes(bytes : Bytes) -> Result[CodeBlockSizeReport, WiteError]

    analyze_component_call_graphs

    fn analyze_component_call_graphs(bytes : Bytes) -> Result[Array[ComponentCallGraphReport], String]

    analyze_component_contract

    fn analyze_component_contract(bytes : Bytes, resolved :
    ResolveInput
    ) -> Result[ContractReport, String]

    analyze_component_core_optimize

    fn analyze_component_core_optimize(bytes : Bytes, config? : OptimizeConfig, exclude? : Array[String]) -> Result[ComponentCoreOptimizeReport, String]

    analyze_component_function_sizes

    fn analyze_component_function_sizes(bytes : Bytes) -> Result[Array[ComponentFunctionSizeReport], String]

    analyze_component_root_policy

    fn analyze_component_root_policy(bytes : Bytes, resolved_wit? :
    ResolveInput
    ?, exclude? : Array[String]) -> Result[ComponentRootPolicyReport, String]

    analyze_dce_report

    fn analyze_dce_report(bytes : Bytes) -> Result[DceReport, WiteError]

    analyze_function_size_gap

    fn analyze_function_size_gap(left_bytes : Bytes, right_bytes : Bytes, top_limit? : UInt) -> Result[FunctionGapReport, WiteError]

    analyze_function_sizes

    fn analyze_function_sizes(bytes : Bytes) -> Result[Array[FunctionSize], WiteError]

    analyze_host_generated_code

    fn analyze_host_generated_code(bytes : Bytes) -> Result[HostGeneratedCodeReport, WiteError]

    analyze_hotness_size_matrix

    fn analyze_hotness_size_matrix(bytes : Bytes, iterations? : UInt, scenarios? : Array[RuntimeProfileScenario]) -> Result[HotnessSizeMatrixReport, String]

    analyze_keep_reasons

    fn analyze_keep_reasons(bytes : Bytes, config? : OptimizeConfig) -> Result[KeepReasonReport, WiteError]

    analyze_optimize_metadata

    fn analyze_optimize_metadata(bytes : Bytes, config? : OptimizeConfig, function_diff_limit? : UInt) -> Result[OptimizeMetadataReport, WiteError]

    analyze_retain_paths

    fn analyze_retain_paths(bytes : Bytes, config? : OptimizeConfig) -> Result[RetainPathReport, WiteError]

    analyze_section_sizes

    fn analyze_section_sizes(bytes : Bytes) -> Result[Array[SectionSize], WiteError]

    analyze_wasm_breakdown

    fn analyze_wasm_breakdown(bytes : Bytes, top_limit? : UInt) -> Result[WasmBreakdownReport, WiteError]

    error_to_string

    fn error_to_string(err : WiteError) -> String

    make_component_optimize_config

    fn make_component_optimize_config(base? : OptimizeConfig, root_name_candidates? : Array[String], exclude? : Array[String]) -> OptimizeConfig

    make_optimize_config

    fn make_optimize_config(strip_all_custom? : Bool, strip_name_section? : Bool, strip_producers_section? : Bool, strip_debug_sections? : Bool, strip_dwarf_sections? : Bool, strip_target_features_section? : Bool, keep_custom_sections? : Array[String], pass_rounds? : UInt, enable_peephole? : Bool, peephole_remove_nop? : Bool, peephole_remove_const_drop? : Bool, enable_vacuum? : Bool, enable_merge_blocks? : Bool, enable_remove_unused_brs? : Bool, enable_dce? : Bool, enable_dfe? : Bool, enable_merge_similar_functions? : Bool, enable_remove_unused_module_elements? : Bool, closed_world? : Bool, closed_world_root_exports? : Array[String], safe_mode? : Bool) -> OptimizeConfig

    make_runtime_profile_scenario

    fn make_runtime_profile_scenario(export_name : String, args? : Array[Int]) -> RuntimeProfileScenario

    optimize_binary_for_size

    fn optimize_binary_for_size(bytes : Bytes, config? : OptimizeConfig, exclude? : Array[String]) -> Result[OptimizeResult, String]

    optimize_component_for_size

    fn optimize_component_for_size(bytes : Bytes, config? : OptimizeConfig, exclude? : Array[String]) -> Result[OptimizeResult, String]

    optimize_config_from_opt_level

    fn optimize_config_from_opt_level(level : String) -> OptimizeConfig?

    optimize_for_size

    fn optimize_for_size(bytes : Bytes, config? : OptimizeConfig) -> Result[OptimizeResult, WiteError]

    profile_component

    fn profile_component(bytes : Bytes) -> Result[ComponentProfile, String]

    profile_module

    fn profile_module(bytes : Bytes) -> Result[ModuleProfile, WiteError]

    profile_runtime_exports

    fn profile_runtime_exports(bytes : Bytes, iterations? : UInt, scenarios? : Array[RuntimeProfileScenario]) -> Result[RuntimeProfile, String]

    profile_runtime_zero_arg_exports

    fn profile_runtime_zero_arg_exports(bytes : Bytes, iterations? : UInt) -> Result[RuntimeProfile, String]

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io