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
Strip out debug fields to reduce memory footprint #22915
Comments
This comment has been minimized.
This comment has been minimized.
@xster |
ah I misunderstood. These are for the actual Dart functions in the framework implementation like Sorry, I totally misunderstood the OP. |
/cc @alexmarkov |
Indeed, Dart AOT compiler can tree shake fields if they are never read. In order to verify how well this optimization works for Flutter debug fields, I looked at debug fields retained on Flutter Gallery (https://github.com/flutter/gallery @ flutter/gallery@c858388), flutter @ 6cb4357. The following simple program dumps all fields which start with import 'dart:io';
import 'package:kernel/ast.dart';
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
class ListDebugFields extends RecursiveVisitor {
@override
visitField(Field node) {
if (node.name.text.startsWith('debug') ||
node.name.text.startsWith('_debug')) {
final cls = node.enclosingClass;
if (cls != null) {
print('${cls.name}.${node.name.text}');
} else {
print('${node.enclosingLibrary.importUri} :: ${node.name.text}');
}
}
}
}
main(List<String> args) async {
final component = new Component();
final List<int> bytes = new File(args[0]).readAsBytesSync();
new BinaryBuilder(bytes).readComponent(component);
ListDebugFields().visitComponent(component);
} In debug mode, Flutter Gallery app.dill contains 230 debug fields. I grepped retained debug fields and found that 32 of those fields are actually used in release mode:
It is possible to change Flutter code to avoid these uses (for example, their uses can be guarded with The following 3 retained debug fields don't have uses in release mode:
These fields are retained because they have initializers and constructors of their classes are retained. |
AOT tree shaker was improved to handle instance fields with initializers at dart-lang/sdk@9c190c5, and tree shaker now removes 3 debug fields which are not used in release mode. The remaining 32 debug fields are not eliminated because they are still used in release mode. |
Fyi @kenzieschmoll. This would be a good use case for the code size tooling. None of the remaining 32 debug fields should be included in release mode but likely there are bugs in Flutter that result in the fields surviving in release mode. |
FWIW we don't really write enough information into either snapshot profile or precompiler trace to connect a retained field back to its uses. |
@gintominto5329 anything specific you are asking about? |
Based on @alexmarkov comments above I think there is nothing planned on the Dart side and all treeshakable fields are now actually treeshaken. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
The Flutter framework defines many
debug*
fields that are only used during debug builds. They are still present in release builds, but mostly unused there. While they don't take up any significant space in the snapshot (8B for hello_world, 6.4KB for flutter_gallery) they may significantly increase our memory footprint when the app runs on device.We should measure what the impact on memory usage is and if it is significant strip those fields out in debug mode - either with a kernel transformer or by extending Dart's treeshakeing-algorithm to remove those unused fields.
/cc @jacob314
The text was updated successfully, but these errors were encountered: