-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason not to use exists()
here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.019898
So it seems the sync methods are ~10 times faster!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.