Files
sdk/tests/lib_2/isolate/vm_rehash_test.dart
T
Martin Kustermann 84dbb6e0b6 [VM] Do eager rehashing of [LinkedHashMap]s in order to avoid checking on every access
This improves 
  * JIT performance by around 14% 
  * precompiled performance by around 2%
on a simple map microbenchmark.

Change-Id: I623e2a715a709f89f2514ae30fbb504ee2e31661
Reviewed-on: https://dart-review.googlesource.com/17165
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-31 13:42:15 +00:00

60 lines
1.4 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:isolate';
int globalHash = 0;
class A {
int get hashCode => globalHash;
bool operator ==(other) => true;
}
final key = new A();
other(SendPort sendPort) async {
// We use a different hash than the main isolate, but the re-hashing on our
// side happens after this line and should therefore also deserialize the map
// with a new hash, so we should be able to find the value in the map.
globalHash = 4321;
final port = new ReceivePort();
sendPort.send(port.sendPort);
final Map map = await port.first;
sendPort.send(map[key]);
port.close();
}
void launchIsolate(argument) {
other(argument);
}
main() async {
final r = new ReceivePort();
final re = new ReceivePort();
final map = {};
globalHash = 1234;
map[key] = 1;
await Isolate.spawn(launchIsolate, r.sendPort, onError: re.sendPort);
re.listen((error) => throw 'Error $error');
final it = new StreamIterator(r);
await it.moveNext();
final SendPort port = it.current;
port.send(map);
await it.moveNext();
final otherIsolateMapEntry = await it.current;
if (map[key] != otherIsolateMapEntry) {
throw "test failed";
}
r.close();
re.close();
}