Skip to content

[vm/ffi] Enable inlining idempotent force-optimized functions #38985

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

Open
dcharkes opened this issue Oct 18, 2019 · 5 comments
Open

[vm/ffi] Enable inlining idempotent force-optimized functions #38985

dcharkes opened this issue Oct 18, 2019 · 5 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-performance Issue relates to performance or code size

Comments

@dcharkes
Copy link
Contributor

The dart:ffi memory operations are on par with dart:typed_data in AoT, but roughly 4x slower in JiT on x64/ia32/arm64/arm.

To get JiT in line, the indexed load/store should be made inlineable in unoptimized code. This is possible, even with code motion, because the index load/store are idempotent operations.

x64 measurements:

$ dart benchmarks/FfiMemory/dart/FfiMemory.dart 
FfiMemory.PointerInt8(RunTime): 72.17852760736196 us.

$ dart ../../golem/golem4/benchmarks/TypedData/dart/TypedData.dart 
TypedData.Int8ListBench(RunTime): 15.412078084904714 us.

$ DART_CONFIGURATION=ReleaseX64 pkg/vm/tool/precompiler2 benchmarks/FfiMemory/dart/FfiMemory.dart bench.dill
$ DART_CONFIGURATION=ReleaseX64 pkg/vm/tool/dart_precompiled_runtime2 bench.dill
FfiMemory.PointerInt8(RunTime): 19.55705275509705 us.

$ DART_CONFIGURATION=ReleaseX64 pkg/vm/tool/precompiler2 ../../golem/golem4/benchmarks/TypedData/dart/TypedData.dart bench.dill
$ DART_CONFIGURATION=ReleaseX64 pkg/vm/tool/dart_precompiled_runtime2 bench.dill
TypedData.Int8ListBench(RunTime): 19.509307113036012 us.
@dcharkes dcharkes added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi labels Oct 18, 2019
@mkustermann mkustermann removed their assignment Oct 20, 2020
@mkustermann
Copy link
Member

We use force-optimized functions outside the FFI. It's a general optimization we'd like to do. Removinglibrary-ffi label.

@alexmarkov
Copy link
Contributor

Also see https://dart-review.googlesource.com/c/sdk/+/210648 for the discussion of inlining force-optimized functions.

@ghost
Copy link

ghost commented May 6, 2022

In 243320 we're using Location::Any() to force handle inputs into FFI calls to be placed on the stack.
But once we start inlining the trampolines we also have to handle the case where inputs can be constants.

@zanderso
Copy link
Member

@rmacnak-google @a-siva We discussed today that this optimization could also reduce the binary size overhead. We saw a ~50KB compressed increase in Flutter app size when switching the Engine to FFI natives.

@mkustermann
Copy link
Member

There will be some other things needed before @FfiNative will benefit from inlining force-optimized functions. @dcharkes might look into those things.

@aam aam added the type-performance Issue relates to performance or code size label Nov 11, 2022
copybara-service bot pushed a commit that referenced this issue Aug 15, 2023
…with 'vm:idempotent' pragma.w

If inlined force-optimized function has to deoptimize, it deoptimizes to before-the-call.

BUG=#38985
TEST=Inliner_InlineForceOptimized, Inliner_InlineAndRunForceOptimized

Change-Id: I6aa4bf1b7ce4d19791132d252e01fc38394c9fcc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317522
Reviewed-by: Martin Kustermann <[email protected]>
Reviewed-by: Slava Egorov <[email protected]>
Commit-Queue: Alexander Aprelev <[email protected]>
Reviewed-by: Alexander Markov <[email protected]>
copybara-service bot pushed a commit that referenced this issue Aug 18, 2023
This is follow-up to https://dart.googlesource.com/sdk/+/54234979a32368c2e6fe5a45468aae939ccc7700

BUG=#38985
TEST=ci
CoreLibraryReviewExempt: vm-specific pragma
Change-Id: Ib24d283634708902bbabfc750c7a4496745e69ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321300
Commit-Queue: Alexander Aprelev <[email protected]>
Reviewed-by: Martin Kustermann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-performance Issue relates to performance or code size
Projects
None yet
Development

No branches or pull requests

5 participants