Cache packageName to base Uri mapping. This makes analysis with using incremental analysis cache 30% faster. Without this change getBase() takes 40% (!) of total analysis time. With this change - just 0.79% of total time. Although the remaining 17% of PackagesBase.resolve() make my cry. Why URI manipulations are SO SLOW?! R=brianwilkerson@google.com, pquitslund@google.com, kevmoo@google.com BUG= Review URL: https://codereview.chromium.org/2041103005 .
diff --git a/pkgs/package_config/lib/src/packages_io_impl.dart b/pkgs/package_config/lib/src/packages_io_impl.dart index db39bdb..0e94746 100644 --- a/pkgs/package_config/lib/src/packages_io_impl.dart +++ b/pkgs/package_config/lib/src/packages_io_impl.dart
@@ -14,10 +14,15 @@ /// A [Packages] implementation based on a local directory. class FilePackagesDirectoryPackages extends PackagesBase { final Directory _packageDir; + final Map<String, Uri> _packageToBaseUriMap = <String, Uri>{}; + FilePackagesDirectoryPackages(this._packageDir); - Uri getBase(String packageName) => - new Uri.file(path.join(_packageDir.path, packageName, '.')); + Uri getBase(String packageName) { + return _packageToBaseUriMap.putIfAbsent(packageName, () { + return new Uri.file(path.join(_packageDir.path, packageName, '.')); + }); + } Iterable<String> _listPackageNames() { return _packageDir
diff --git a/pkgs/package_config/pubspec.yaml b/pkgs/package_config/pubspec.yaml index 80aea6d..3d9bd45 100644 --- a/pkgs/package_config/pubspec.yaml +++ b/pkgs/package_config/pubspec.yaml
@@ -1,5 +1,5 @@ name: package_config -version: 0.1.4 +version: 0.1.5 description: Support for working with Package Resolution config files. author: Dart Team <misc@dartlang.org> homepage: https://github.com/dart-lang/package_config