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

prefer-inline pragmas are not sufficient to do the inlining we want #59685

Open
osa1 opened this issue Dec 7, 2024 · 0 comments
Open

prefer-inline pragmas are not sufficient to do the inlining we want #59685

osa1 opened this issue Dec 7, 2024 · 0 comments
Labels
area-dart2wasm Issues for the dart2wasm compiler. type-performance Issue relates to performance or code size

Comments

@osa1
Copy link
Member

osa1 commented Dec 7, 2024

import 'dart:typed_data';

@pragma("wasm:prefer-inline")
int sum(List<int> list) {
  int ret = 0;
  for (int i = 0; i < list.length; i += 1) {
    ret += list[i];
  }
  return ret;
}

void main() {
  Int64List intList = Int64List.fromList([1, 2, 3, 4]);
  sum(intList);
  sum([1, 2, 3, 4]);
}

Ideally we want all direct calls to Int64List.[] to be inlined:

@override
@pragma("wasm:prefer-inline")
int operator [](int index) {
indexCheck(index, length);
return _data.read(_offsetInElements + index);
}

But when a call becomes direct after wasm-opt, because we can't control wasm-opt's inliner with a similar pragma, it's not inlined. Relevant parts of the output of the code above:

(func $main (;297;)
  ...
  loop $label1
    local.get $var7
    call $_WasmI64ArrayBase.length initializer
    local.get $var2
    i64.gt_s
    if
      local.get $var4
      local.get $var7
      local.get $var2
      call $I64List.[]
      ref.cast $BoxedInt
      struct.get $BoxedInt $field1
      i64.add
      local.set $var4
      local.get $var2
      i64.const 1
      i64.add
      local.set $var2
      br $label1
    end
  end $label1
  ...
)

Becuase [] is not inlined, each access to the array boxes the integer in the array before returning.

@osa1 osa1 added the area-dart2wasm Issues for the dart2wasm compiler. label Dec 7, 2024
@lrhn lrhn added the type-performance Issue relates to performance or code size label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart2wasm Issues for the dart2wasm compiler. type-performance Issue relates to performance or code size
Projects
None yet
Development

No branches or pull requests

2 participants