Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Wasm: Make class fields immutable at the Wasm level #5039

Open
Labels
optimizationOptimization only. Does not affect semantics or correctness.wasmApplies to the WebAssembly backend only
@tanishiking

Description

@tanishiking

Currently, all class fields are mutable at the Wasm level: thegenFunctionID.newDefault function creates a class instance with fields initialized to their zero values, and then the constructor initializes them (byAssign at the IR level).

valfields= classInfo.allFieldDefs.map { field=>
watpe.StructField(
genFieldID.forClassInstanceField(field.name.name),
makeDebugName(ns.InstanceField, field.name.name),
transformFieldType(field.ftpe),
isMutable=true// initialized by the constructors, so always mutable at the Wasm level
)
}

Fields being mutable means that accessing a field is an impure operation at the Wasm level, causing us to miss some optimization opportunities.
In fact, making itables immutable has improved performance in some benchmarks, as seen in#5038.

We may want to "merge" thegenFunctionID.newDefault function with the constructor: The fused constructor would:

  • Set up the vtable (virtual method table) and itable (interface table)
  • Initialize the fields
    • Instead of filling fields with zero values, thewasmemitter would transform the RHS of fieldAssign nodes to become the initial values of the fields.
  • Executestruct.new for instantiation (asnewDefault currently does)

Alternatively, should we modify the IR structure somehow? It appears that theseAssign operations in the constructor originate from Scala compiler, not fromGenJSCode🤷. In this case, making changes at the IR level seems introduce more complications than it solves.

Metadata

Metadata

Assignees

No one assigned

    Labels

    optimizationOptimization only. Does not affect semantics or correctness.wasmApplies to the WebAssembly backend only

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp