Webdev: Look for pubspec.yaml next to .dart_tool/package_config.json instead of only current dir#2498
Conversation
| '.dart_tool', | ||
| 'package_config.json', | ||
| ); | ||
| if (File(candidate).existsSync()) break; |
There was a problem hiding this comment.
Any particular reason not to use exists() here instead?
There was a problem hiding this comment.
Not really - I believe I once learnt that the async overhead is a lot larger than doing the stat itself - but I doubt it makes any difference.
Do you prefer the async method?
There was a problem hiding this comment.
This little program seems to confirm it:
import 'dart:io';
main() async {
final s = Stopwatch()..start();
for (var i = 0; i < 10000; i++) {
await File('abc').exists();
}
print('async ${s.elapsed}');
s.reset();
for (var i = 0; i < 10000; i++) {
File('abc').existsSync();
}
print(' sync ${s.elapsed}');
}> dart --version
Dart SDK version: 3.6.0-271.0.dev (dev) (Mon Sep 23 21:07:16 2024 -0700) on "linux_x64"
> dart bin/exists.dart
async 0:00:00.233795
sync 0:00:00.019898So it seems the sync methods are ~10 times faster!
There was a problem hiding this comment.
Ah right, sync operations are definitely faster at the cost of blocking the thread from handling other asynchronous work. This is probably fine in this situation since I doubt we're doing any interesting asynchronous work while we're also looking for the package_config. Thanks for checking!
|
I'll land this - we can do the async switch in a follow-up if needed |
#2496
I think we should consider also doing #2497.