Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Issue 2379733002: Recognize and optimize a.runtimeType == b.runtimeType pattern. (Closed)

Created:
4 years, 2 months ago by Vyacheslav Egorov (Google)
Modified:
4 years, 1 month ago
CC:
reviews_dartlang.org, vm-dev_dartlang.org, sra1
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Recognize and optimize a.runtimeType == b.runtimeType pattern. Start by removing all get:runtimeType overrides in the patch files to have a single point computing the runtime type - Object.get:runtimeType. Handle string, double and integer types inside both intrinsic and runtime call to unify their handling and guarantee that code works even with intrinsifier disabled. With overrides removed we can easily check that get:runtimeType is unique function name within the application that is being precompiled and use that to convert InstanceCall(get:runtimeType, ...) into StaticCall even nothing is known about the receiver. This enables us to check if both left side and right side of comparison are StaticCall(Object.get:runtimeType, ...) when specializing InstanceCall(==, x, y). If they are we convert InstanceCall(==, StaticCall(get:runtimeType, a), StaticCall(get:runtimeType, b)) into StaticCall(Object._hasSameRuntimeType, a, b). A canonicalization rule will later delete unused get:runtimeType invocations. Object._hasSameRuntimeType is implemented in C++ and intrinsified. It operates without creating new runtime types (except for Closures - where it does for simplicity). Cases of different class ids (i.e. a.[cid] != b.[cid]) and non-parameterized types are handled completely in the intrinsic. The rest is handled in the runtime code. Microbenchmarking results: Same parameterized classes: 15x improvement Different parameterized classes: 300x improvement Different/same non-parameterized classes: 2x improvement BUG= R=fschneider@google.com, regis@google.com Committed: https://github.com/dart-lang/sdk/commit/f4ec20abac2286604565e9d5a6d1d744849c964d

Patch Set 1 #

Patch Set 2 : Done #

Patch Set 3 : Done #

Total comments: 21

Patch Set 4 : Support polymorphic inlining of Object.get:runtimeType #

Total comments: 6

Patch Set 5 : Address Florian's comment re VisitInstanceCall #

Patch Set 6 : port to all arch, make AOT opt non-speculative #

Total comments: 23

Patch Set 7 : fix lint #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1113 lines, -71 lines) Patch
M runtime/lib/double.dart View 1 chunk +0 lines, -2 lines 0 comments Download
M runtime/lib/integers.dart View 1 chunk +0 lines, -2 lines 0 comments Download
M runtime/lib/object.cc View 1 2 3 4 5 6 1 chunk +44 lines, -2 lines 0 comments Download
M runtime/lib/object_patch.dart View 1 chunk +2 lines, -0 lines 0 comments Download
M runtime/lib/string_patch.dart View 1 chunk +0 lines, -2 lines 0 comments Download
M runtime/vm/aot_optimizer.h View 1 2 3 4 5 6 3 chunks +8 lines, -1 line 0 comments Download
M runtime/vm/aot_optimizer.cc View 1 2 3 4 5 6 6 chunks +107 lines, -6 lines 0 comments Download
M runtime/vm/bootstrap_natives.h View 1 chunk +1 line, -0 lines 0 comments Download
M runtime/vm/compiler.cc View 1 2 3 4 5 6 2 chunks +4 lines, -2 lines 0 comments Download
M runtime/vm/flow_graph.cc View 1 chunk +8 lines, -0 lines 0 comments Download
M runtime/vm/flow_graph_inliner.h View 3 chunks +4 lines, -1 line 0 comments Download
M runtime/vm/flow_graph_inliner.cc View 1 2 3 4 5 6 3 chunks +36 lines, -3 lines 0 comments Download
M runtime/vm/intermediate_language.h View 1 2 3 4 5 6 2 chunks +5 lines, -0 lines 0 comments Download
M runtime/vm/intermediate_language.cc View 1 2 3 4 5 6 1 chunk +61 lines, -0 lines 0 comments Download
M runtime/vm/intrinsifier_arm.cc View 1 2 3 4 5 6 2 chunks +145 lines, -3 lines 0 comments Download
M runtime/vm/intrinsifier_arm64.cc View 1 2 3 4 5 6 2 chunks +145 lines, -3 lines 0 comments Download
M runtime/vm/intrinsifier_ia32.cc View 1 2 3 4 5 6 2 chunks +157 lines, -4 lines 0 comments Download
M runtime/vm/intrinsifier_mips.cc View 1 2 3 4 5 6 2 chunks +150 lines, -3 lines 0 comments Download
M runtime/vm/intrinsifier_x64.cc View 1 2 3 4 5 6 2 chunks +155 lines, -4 lines 0 comments Download
M runtime/vm/isolate.h View 1 2 3 4 5 6 1 chunk +3 lines, -0 lines 0 comments Download
M runtime/vm/jit_optimizer.cc View 1 2 3 1 chunk +11 lines, -4 lines 0 comments Download
M runtime/vm/method_recognizer.h View 1 2 3 4 5 6 2 chunks +2 lines, -0 lines 0 comments Download
M runtime/vm/object.cc View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M runtime/vm/object_store.h View 3 chunks +10 lines, -2 lines 0 comments Download
M runtime/vm/precompiler.h View 3 chunks +14 lines, -3 lines 0 comments Download
M runtime/vm/precompiler.cc View 1 2 3 4 5 6 14 chunks +38 lines, -23 lines 0 comments Download
M runtime/vm/symbols.h View 1 chunk +2 lines, -0 lines 0 comments Download

Messages

Total messages: 21 (4 generated)
Vyacheslav Egorov (Google)
Please take the first look. Intrinsic only implemented on x64 for now. I will port ...
4 years, 2 months ago (2016-09-28 20:55:26 UTC) #3
Florian Schneider
First round of comments. I like the overall approach. https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object.cc File runtime/lib/object.cc (right): https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object.cc#newcode155 runtime/lib/object.cc:155: ...
4 years, 2 months ago (2016-09-28 22:49:24 UTC) #4
Vyacheslav Egorov (Google)
https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object.cc File runtime/lib/object.cc (right): https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object.cc#newcode155 runtime/lib/object.cc:155: if (!cls.IsGeneric() || (cls.NumTypeArguments() <= 0)) { On 2016/09/28 ...
4 years, 2 months ago (2016-09-29 00:31:22 UTC) #5
siva
https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object_patch.dart File runtime/lib/object_patch.dart (right): https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object_patch.dart#newcode54 runtime/lib/object_patch.dart:54: @patch Type get runtimeType native "Object_runtimeType"; One could recover ...
4 years, 2 months ago (2016-09-29 02:28:20 UTC) #7
Vyacheslav Egorov (Google)
PTAL New patch set adds polymorphic inlining of Object.get:runtimeType to guarantee good performance in cases ...
4 years, 2 months ago (2016-09-29 15:01:44 UTC) #8
Florian Schneider
https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object_patch.dart File runtime/lib/object_patch.dart (right): https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object_patch.dart#newcode54 runtime/lib/object_patch.dart:54: @patch Type get runtimeType native "Object_runtimeType"; On 2016/09/29 15:01:43, ...
4 years, 2 months ago (2016-09-29 18:03:29 UTC) #9
Vyacheslav Egorov (Google)
https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object_patch.dart File runtime/lib/object_patch.dart (right): https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object_patch.dart#newcode54 runtime/lib/object_patch.dart:54: @patch Type get runtimeType native "Object_runtimeType"; On 2016/09/29 18:03:28, ...
4 years, 2 months ago (2016-09-30 09:56:28 UTC) #10
Vyacheslav Egorov (Google)
I ported to ARM and did a quick measurement on Flutter: this CL improves layout ...
4 years, 2 months ago (2016-09-30 17:03:04 UTC) #11
Florian Schneider
https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object_patch.dart File runtime/lib/object_patch.dart (right): https://codereview.chromium.org/2379733002/diff/40001/runtime/lib/object_patch.dart#newcode54 runtime/lib/object_patch.dart:54: @patch Type get runtimeType native "Object_runtimeType"; On 2016/09/30 09:56:27, ...
4 years, 2 months ago (2016-09-30 17:42:56 UTC) #12
Vyacheslav Egorov (Google)
This is ready for the review. Main changes in this revision: (1) AOT optimization is ...
4 years, 2 months ago (2016-10-04 17:59:42 UTC) #13
Vyacheslav Egorov (Google)
friendly ping :)
4 years, 2 months ago (2016-10-06 09:35:23 UTC) #14
Florian Schneider
Lgtm https://codereview.chromium.org/2379733002/diff/100001/runtime/lib/object.cc File runtime/lib/object.cc (right): https://codereview.chromium.org/2379733002/diff/100001/runtime/lib/object.cc#newcode155 runtime/lib/object.cc:155: if (!cls.IsGeneric() || (cls.NumTypeArguments() == 0)) { Could ...
4 years, 2 months ago (2016-10-06 18:03:20 UTC) #15
regis
lgtm with a few comments https://codereview.chromium.org/2379733002/diff/100001/runtime/lib/object.cc File runtime/lib/object.cc (right): https://codereview.chromium.org/2379733002/diff/100001/runtime/lib/object.cc#newcode155 runtime/lib/object.cc:155: if (!cls.IsGeneric() || (cls.NumTypeArguments() ...
4 years, 2 months ago (2016-10-08 09:10:37 UTC) #16
Vyacheslav Egorov (Google)
Thanks for the reviews. https://codereview.chromium.org/2379733002/diff/100001/runtime/lib/object.cc File runtime/lib/object.cc (right): https://codereview.chromium.org/2379733002/diff/100001/runtime/lib/object.cc#newcode155 runtime/lib/object.cc:155: if (!cls.IsGeneric() || (cls.NumTypeArguments() == ...
4 years, 1 month ago (2016-10-24 20:23:03 UTC) #17
Vyacheslav Egorov (Google)
Committed patchset #7 (id:120001) manually as f4ec20abac2286604565e9d5a6d1d744849c964d (presubmit successful).
4 years, 1 month ago (2016-10-25 08:03:11 UTC) #19
zra
On 2016/10/25 08:03:11, Vyacheslav Egorov (Google) wrote: > Committed patchset #7 (id:120001) manually as > ...
4 years, 1 month ago (2016-10-25 11:48:06 UTC) #20
Vyacheslav Egorov (Google)
4 years, 1 month ago (2016-10-25 15:09:54 UTC) #21
Message was sent while issue was closed.
On 2016/10/25 11:48:06, zra wrote:
> On 2016/10/25 08:03:11, Vyacheslav Egorov (Google) wrote:
> > Committed patchset #7 (id:120001) manually as
> > f4ec20abac2286604565e9d5a6d1d744849c964d (presubmit successful).
> 
> It looks like this change causes some problems with DBC:
> 
> FAILED: none-vm-checked debug_simdbc64
> language/first_class_types_literals_test/01
> Expected: Pass 
> Actual: RuntimeError
> CommandOutput[vm]:
> 
> stderr:
> Unhandled exception:
> Expect.equals(expected: <int>, actual: <int>) fails.
> #0      Expect._fail (package:expect/expect.dart:435:5)
> #1      Expect.equals (package:expect/expect.dart:102:5)
> #2      main
>
(file:///usr/local/google/home/zra/dart/sdk/out/DebugSIMDBC64/generated_tests/language/first_class_types_literals_test_01.dart:40:10)
> #3      _startIsolate.<anonymous closure>
> (dart:isolate-patch/isolate_patch.dart:261)
> #4      _RawReceivePortImpl._handleMessage
> (dart:isolate-patch/isolate_patch.dart:148)
> 
> 
> Command[vm]: DART_CONFIGURATION=DebugSIMDBC64 out/DebugSIMDBC64/dart
> --enable_asserts --enable_type_checks --ignore-unrecognized-flags
> --packages=.packages
>
out/DebugSIMDBC64/generated_tests/language/first_class_types_literals_test_01.dart

Thanks! I will dig into this in the evening. The exception is very confusing
though - looks like some int type is not canonicalized(?).

Powered by Google App Engine
This is Rietveld 408576698