Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

Fuzion Optimizer

Specialization

The goal of specialization is to avoid overhead for dynamic binding and heap allocation. Take this example:

x i32 := ...

stdout.println("x is " + x)

with

println(s ref String) is
  for b in s.as_bytes
    write b

and

String.infix + (s ref String) is
  .. create iterator over String.this followed by iterator over s

The performance issues here are:

  • Dynamic binding for call to stdout.println
  • Dynamic binding for calls to s.as_bytes and has_next / next
  • Heap allocation for String.infix +

to solve this, we need

Data Flow Analysis

With DFA, we can avoid the dynamic call at stdout.println, we could even inline this call.

Specialization for Parameters

Once we have no dynamic binding, we can specialize calls for concrete values of parameters. In this case, we know that println is called with an instance of String.infix +, which does not need to be heap allocated.

Inlining

Now that println was specialized for String.infix +, we can inline String.infix + and directly call the iterators of the string and i32.

Repeat

Finally, we can continue this specialization and inlining for the string and the i32 and completely avoid any heap allocation and dynamic binding

Allocation of Closures: Funarg problem.

Fuom should provide a solution to the Funarg problem: It should find what inner fields in a feature are part of a closure and what is the lifespan of this closure? If the lifespan does not exceed the lifespan of the call of the outer feature of these fields, they can be stack allocated. Otherwise, it might be possible to allocate them in the stack frame of outer features, place copies of immutable fields into the funarg instance (which might itself be a value type and stack allocated), or, as a last resort, heap allocate the memory for these fields.

last changed: 2024-06-28