[vm] Mark _OperatorEqualsAndHashCode._hashCode for inlining

In a valgrind "profile" of a run of an aot-compiled version of
`pkg/analyzer/tool/stable_analysis.dart` I noticed that
`_OperatorEqualsAndHashCode._hashCode` was called 40,288,281 times,
costing - by itself, i.e. without the actual cost of getting the
underlying hashCode - 723,483,274 instructions - about 1.79% of the
total cost.

Interestingly `_OperatorEqualsAndHashCode._equals` wasn't there, so that
one must be inlined (whereas the `_hashCode` isn't). Stepping via GDB
confirms both things.

Via the inlining tracing in the vm via

```
out/ReleaseX64/dart-sdk/bin/dart \
compile aot-snapshot --verbose \
--extra-gen-snapshot-options="--print_inlining_tree" \
pkg/analyzer/tool/stable_analysis.dart
```

I found

```
Inlining into: 'dart:_compact_hash___Map&_LinkedHashBase&MapMixin&_HashBase&_OperatorEqualsAndHashCode&_LinkedHashMapMixin@3099033_[]='
    growth: 0.000000 (9 -> 0)
  NO 14 __Map&_LinkedHashBase&MapMixin&_HashBase&_OperatorEqualsAndHashCode@3099033._hashCode@3099033 - Heuristic fail (no small leaf)
  NO 16 __Map&_LinkedHashBase&MapMixin&_HashBase&_OperatorEqualsAndHashCode&_LinkedHashMapMixin@3099033._set@3099033 - Not inlinable
```

In `runtime/vm/compiler/backend/inliner.cc` I saw that I could avoid
this "no small leaf" thing by marking it for inlining.

Running stable_analysis through `perf stat` without and with this CL I
get:

```
Without CL:
    39,552,232,456      instructions:u
    39,552,392,619      instructions:u
    39,554,905,123      instructions:u
```

```
With this CL:
    39,024,836,004      instructions:u
    39,022,158,372      instructions:u
    39,022,782,198      instructions:u
```

So this "only" saves something like 527 million instructions (~1.3%),
i.e. less than the ~723 million instructions hoped for, but I'll take
it.

Change-Id: I07a8fb097e46ab48c26bcf7896b12c7312ededc3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509000
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
This commit is contained in:
Jens Johansen
2026-06-03 07:11:18 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 80f770eb57
commit 7cc5515a6a
@@ -281,6 +281,7 @@ abstract class _EqualsAndHashCode {
}
mixin _OperatorEqualsAndHashCode implements _EqualsAndHashCode {
@pragma("vm:prefer-inline")
int _hashCode(Object? e) => e.hashCode;
bool _equals(Object? e1, Object? e2) => e1 == e2;
}