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

Issue 2024543002: Tweaks for Iterable.toList() invocations. (Closed)

Created:
4 years, 6 months ago by scheglov
Modified:
4 years, 6 months ago
Reviewers:
sra1, Brian Wilkerson
CC:
reviews_dartlang.org
Base URL:
git@github.com:dart-lang/sdk.git@master
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Patch Set 1 #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+12 lines, -14 lines) Patch
M pkg/analyzer/lib/src/dart/element/element.dart View 9 chunks +12 lines, -14 lines 2 comments Download

Messages

Total messages: 7 (2 generated)
scheglov
4 years, 6 months ago (2016-05-29 20:28:09 UTC) #1
Brian Wilkerson
lgtm
4 years, 6 months ago (2016-05-30 15:17:45 UTC) #2
scheglov
Committed patchset #1 (id:1) manually as c33d8cb1692382efe0f5e8372bf219cb92309ac2 (presubmit successful).
4 years, 6 months ago (2016-05-30 19:42:38 UTC) #4
sra1
https://codereview.chromium.org/2024543002/diff/1/pkg/analyzer/lib/src/dart/element/element.dart File pkg/analyzer/lib/src/dart/element/element.dart (right): https://codereview.chromium.org/2024543002/diff/1/pkg/analyzer/lib/src/dart/element/element.dart#newcode4948 pkg/analyzer/lib/src/dart/element/element.dart:4948: HashSet<LibraryElement> visibleLibraries = new HashSet<LibraryElement>(); Ideally the default implementations ...
4 years, 6 months ago (2016-05-31 06:43:57 UTC) #6
scheglov
4 years, 6 months ago (2016-05-31 15:41:37 UTC) #7
Message was sent while issue was closed.
https://codereview.chromium.org/2024543002/diff/1/pkg/analyzer/lib/src/dart/e...
File pkg/analyzer/lib/src/dart/element/element.dart (right):

https://codereview.chromium.org/2024543002/diff/1/pkg/analyzer/lib/src/dart/e...
pkg/analyzer/lib/src/dart/element/element.dart:4948: HashSet<LibraryElement>
visibleLibraries = new HashSet<LibraryElement>();
On 2016/05/31 06:43:56, sra1 wrote:
> Ideally the default implementations would also be most efficient for normal
> usage.
> 
> Do you have evidence that that this is not the case?
> The VM implementation of LinkedHashSet (i.e. Set) is more storage-efficient
that
> HashSet for more than a 2-3 elements, but I don't know if that translates to
> overall performance.
> 
> 


The following performance micro-benchmark uses 67 ms with Set, and 46 ms with
HashSet.
So it seems that HashSet wins.


---------------------
import 'dart:math';
import 'dart:collection';

main() {
  new Benchmark(100, () {
    for (int i = 0; i < 1000000; i++) {
//      HashSet<int> set = new HashSet<int>();
      Set<int> set = new Set<int>();
      set.add(1);
      set.add(2);
      set.toList(growable: false);
    }
  }).run();
}

typedef void BenchmarkIteration();

class Benchmark {
  final int iterationCount;
  final BenchmarkIteration iteration;

  Benchmark(this.iterationCount, this.iteration);

  void run() {
    int best = 1 << 20;
    for (int i = 0; i < iterationCount; i++) {
      Stopwatch sw = new Stopwatch()..start();
      iteration();
      best = min(sw.elapsedMilliseconds, best);
    }
    print('Best time: $best ms.');
  }
}
---------------------

Powered by Google App Engine
This is Rietveld 408576698