When clicking the "toplist by retained memory" button in Observatory
it always asks to find 10 objects of a specific size.
The previous implementation did this by taking all objects (millions if
using a lot of memory), sorting it (O(n log n)), filtering it (O(n)),
and ".take"ing the 10 we wanted. Total runtime should be O(n log n)
where n is the number of objects in the heap.
This CL optimizes this for the (to my knowledge) only case there exists,
and instead, while iterationg over all elements (O(n)) keeps a sorted
working list of the top m objects (this is 10 for all intents and purpose
as far as I can see; I've if-cased it to be at most 20). Total runtime
should be O(n log m) where n is the number of objects in the heap and m
is the requested number, which - as said - is at most 20, i.e. a constant,
maying that the runtime is more like O(n).
Instrumenting the code slightly to measure how long it takes:
```
diff --git a/runtime/observatory/lib/src/repositories/top_retaining_instances.dart b/runtime/observatory/lib/src/repositories/top_retaining_instances.dart
index 400ac1427ed..b7e5c429fac 100644
--- a/runtime/observatory/lib/src/repositories/top_retaining_instances.dart
+++ b/runtime/observatory/lib/src/repositories/top_retaining_instances.dart
@@ -7,6 +7,8 @@ part of repositories;
class TopRetainingInstancesRepository
implements M.TopRetainingInstancesRepository {
Future<Iterable<M.RetainingObject>> get(M.IsolateRef i, M.ClassRef c) async {
+ Stopwatch stopwatch = new Stopwatch()..start();
+ try {
S.Isolate isolate = i as S.Isolate;
S.Class cls = c as S.Class;
assert(isolate != null);
@@ -18,5 +20,9 @@ class TopRetainingInstancesRepository
return (await Future.wait(
snapshot.getMostRetained(isolate, classId: cls.vmCid, limit: 10)))
.map((object) => new S.RetainingObject(object));
+ } finally {
+ int ms = stopwatch.elapsedMilliseconds;
+ print("TopRetainingInstancesRepository took $ms ms.");
+ }
}
}
```
I ran this program:
```
import "dart:isolate";
List<Object> data = [];
main() {
RawReceivePort preventClose = new RawReceivePort();
for(int i = 0; i < 10000000; i++) {
data.add(new List<int>()..add(i));
}
for(int i = 0; i < 100000; i++) {
data.add(new Foo(i));
}
}
class Foo {
final int i;
Foo(this.i);
}
```
and requested the toplist by retained memory for class `Foo`.
What before took 121778 ms now takes 81026 ms.
(For smaller numbers in the same test it went from ~10 seconds to ~8 seconds).
Change-Id: I6aee4b0c91af8a9ade116b79e56d1e6cbbee5d09
Reviewed-on: https://dart-review.googlesource.com/70502
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Prior to this fix I get errors like
```
TypeError: Instance of 'b2<bQ>': type 'b2<bQ>' is not a subtype of type 'List<bQ>'
StackTrace:
main.dart.js 1631:3 Object.m
main.dart.js 2001:9 Object.p
[...]
```
Change-Id: I2fc6329c05cb76bff76929aeee1eca3954fbc0a9
Reviewed-on: https://dart-review.googlesource.com/70501
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
- Fix crash related to missing nodes in Heap Snapshot
- Disabled update on GC. With the new idle GC the page was updating too
often.
Change-Id: I8a3aaf9540ff224a5e8119303c8e8ef79e8a73f1
Reviewed-on: https://dart-review.googlesource.com/5327
Commit-Queue: Carlo Bernaschina <cbernaschina@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
An object A is said to be owned by object B if all direct references to A come from B. In particular, an object that holds unshared lists and maps will own the heap size of those lists and maps, as well as any unshared elements. We hope a table of owned sizes will be more useful than a table of shallow sizes, since the latter typically says the heap is mostly lists.
R=cbernaschina@google.com
Review-Url: https://codereview.chromium.org/3009743003 .
Fix observatory tests broken by running dartfmt due to line and column changes.
Temporarily reverted formatting for evaluate_activation_test.dart as dartfmt doesn't yet handle multitests.
BUG=
R=johnmccutchan@google.com
Review-Url: https://codereview.chromium.org/2759973004 .
I've omitted files where the formatter output is significantly uglier
than the original code and I'll send those files in a separate CL
with options for how to make the code look reasonable while still
taking advantage of the formatter.
BUG=
R=johnmccutchan@google.com
Review-Url: https://codereview.chromium.org/2751423005 .
[1] has worse upper bound complexity than [2] but has lower
overhead. With [1] dart2js heaps would converge in ~10 iterations, but
with analyzer heaps would take ~10k iterations.
This reduces the time to analyze the final heap of the analyzer
analyzing dart2js from ~30 minutes to 26 seconds.
Increases peak memory usage by 21N bytes plus O(2N) words.
[1] "A Simple, Fast Dominance Algorithm." Keith D. Cooper, Timothy
J. Harvey, and Ken Kennedy.
[2] "A Fast Algorithm for Finding Dominators in a Flowgraph."
T. Lengauer and R. E. Tarjan.
R=johnmccutchan@google.com
Review URL: https://codereview.chromium.org/1449243002 .
- Dominator tree with retained sizes
- Merge nodes by class
- Split snapshot into chunks so the browser's websockets implementation can handle them.
- Use TypedData indexed by node ids instead of lists of objects and a higher time complexity but more memory efficient algorithm to find the dominator tree (reduces memory usage to ~2X the size of the heap being analyzed from >10X).
R=johnmccutchan@google.com, koda@google.com
Review URL: https://codereview.chromium.org//1124153006
2) Move observatory from runtime/bin/vmservice/observatory to runtime/observatory
3) Add two tools scripts:
- tools/run_pub.py (runs pub before SDK is built)
- tools/obs_tool.py (helper for get, build, and deploy stages)
4) Build Observatory with runtime:
- pub get --offline
- pub build
- deploy
5) Build artifacts are now in standard output directory, for example, out/DebugIA32/observatory.
6) Add a new 'dart_boostrap' host target (no snapshot, no observatory) that can be used as the Dart executable to run pub when building Observatory. This is behind a build.py flag --use-bootstrap-for-observatory because:
- It is only necessary on older Linux distributions that are incompatible with the prebuilt Dart testing executable.
- running pub build with the boostrap Debug build is significantly slower.
7) Detect if the prebuilt executable doesn't work and automatically switch to the 'dart_bootstrap' executable. Also, warn the user and provide a Wiki link with more information.
R=turnidge@google.com
Review URL: https://codereview.chromium.org//810623005
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42614 260f80e4-7a28-3924-810f-c04153c831b5